-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday15.py
49 lines (40 loc) · 1.27 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
from collections import namedtuple
from itertools import product
import itertools
"""
Sprinkles: capacity 5, durability -1, flavor 0, texture 0, calories 5
PeanutButter: capacity -1, durability 3, flavor 0, texture 0, calories 1
Frosting: capacity 0, durability -1, flavor 4, texture 0, calories 6
Sugar: capacity -1, durability 0, flavor 0, texture 2, calories 8
"""
# Ingredient = namedtuple('Ingredient', ['capacity', 'durability', 'flavor', 'texture', 'calories'])
class Ingredient():
def __init__(self, **props):
self.props = list(props.values())
ins = [
[5, -1, 0, 0, 5],
[-1, 3, 0, 0, 1],
[0, -1, 4, 0, 6],
[-1, 0, 0, 2, 8],
]
PROP_COUNT = len(ins[0])
INS_COUNT = len(ins)
ret = 0
cnt = [0, 0, 0, 0]
for cnt in itertools.product(range(101), range(101), range(101)):
if sum(cnt)>100:
continue
cnt = (*cnt, 100-sum(cnt))
total = 1
total_cal = sum(c * i[PROP_COUNT-1] for c, i in zip(cnt, ins))
if total_cal!=500: # part b condition
continue # part b condition
for prop_idx in range(PROP_COUNT-1):
prop_total = sum(c * i[prop_idx] for c, i in zip(cnt, ins))
prop_total = max(prop_total, 0)
total = total * prop_total
ret = max(total, ret)
print(ret)
# 13882464
# 5585580000
# 6211814400