-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay15.py
67 lines (56 loc) · 1.84 KB
/
Day15.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
with open("Day15input.txt") as f:
data = f.readlines()
def gen(result_list, current_buckets, bucket_n, left):
if bucket_n == len(current_buckets)-1:
current_buckets[bucket_n] = left
result_list.append(current_buckets[:])
else:
for i in range(left+1):
current_buckets[bucket_n] = i
gen(result_list, current_buckets, bucket_n + 1, left - i)
def generate(buckets, maximum):
result_list = []
current_buckets = [0]*buckets
gen(result_list, current_buckets, 0, maximum)
return result_list
ingredients = []
for line in data:
words = line.replace(",", " ").split()
props = {words[1]: int(words[2]), words[3]: int(words[4]), words[5]: int(words[6]), words[7]: int(words[8]), words[9]: int(words[10])}
ingredients.append(props)
possibilities = generate(len(data), 100)
max_score = 0
max_score_500 = 0
for p in possibilities:
capacity = 0
for i, amount in enumerate(p):
capacity += amount * ingredients[i]["capacity"]
if capacity < 0:
capacity = 0
durability = 0
for i, amount in enumerate(p):
durability += amount * ingredients[i]["durability"]
if durability < 0:
durability = 0
flavor = 0
for i, amount in enumerate(p):
flavor += amount * ingredients[i]["flavor"]
if flavor < 0:
flavor = 0
texture = 0
for i, amount in enumerate(p):
texture += amount * ingredients[i]["texture"]
if texture < 0:
texture = 0
calories = 0
for i, amount in enumerate(p):
calories += amount * ingredients[i]["calories"]
if calories < 0:
calories = 0
score = capacity * durability * flavor * texture
if score > max_score:
max_score = score
if score > max_score_500 and calories == 500:
max_score_500 = score
print(max_score)
print(max_score_500)