Skip to content

Commit 6c23ac4

Browse files
committed
+day15
1 parent 1c53b06 commit 6c23ac4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

day15/input.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Sprinkles: capacity 2, durability 0, flavor -2, texture 0, calories 3
2+
Butterscotch: capacity 0, durability 5, flavor -3, texture 0, calories 3
3+
Chocolate: capacity 0, durability 0, flavor 5, texture -1, calories 8
4+
Candy: capacity 0, durability -1, flavor 0, texture 5, calories 8

day15/solution.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def main():
2+
# Sprinkles: capacity 2, durability 0, flavor -2, texture 0, calories 3
3+
# Butterscotch: capacity 0, durability 5, flavor -3, texture 0, calories 3
4+
# Chocolate: capacity 0, durability 0, flavor 5, texture -1, calories 8
5+
# Candy: capacity 0, durability -1, flavor 0, texture 5, calories 8
6+
ingredients = [{'cap': 2, 'dur': 0, 'fla': -2, 'tex': 0, 'cal': 3},
7+
{'cap': 0, 'dur': 5, 'fla': -3, 'tex': 0, 'cal': 3},
8+
{'cap': 0, 'dur': 0, 'fla': 5, 'tex': -1, 'cal': 8},
9+
{'cap': 0, 'dur': -1, 'fla': 0, 'tex': 5, 'cal': 8}]
10+
11+
def prop_score(prop, s, b, c, a):
12+
return max(0, sum([ingredients[i][prop] * ingr for (i, ingr) in [(0, s),(1, b),(2, c),(3, a)]]))
13+
14+
score = 0
15+
score_cal = 0
16+
for s in xrange(1, 100):
17+
for b in xrange(1, 100 - s):
18+
for c in xrange(1, 100 - s - b):
19+
a = 100 - s - b - c
20+
props = []
21+
for prop in ['cap', 'dur', 'fla', 'tex']:
22+
props.append(prop_score(prop, s, b, c, a))
23+
new_score = reduce(lambda x, y: x * y, props, 1)
24+
score = max(score, new_score)
25+
if prop_score('cal', s, b, c, a) == 500:
26+
score_cal = max(score_cal, new_score)
27+
print(score)
28+
print(score_cal)
29+
30+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
 (0)