99 Butterscotch: capacity -1, durability -2, flavor 6, texture 3, calories 8
1010Cinnamon: capacity 2, durability 3, flavor -2, texture -1, calories 3"""
1111
12- LineType = int
13- InputType = list [LineType ]
1412PROPERTIES = "capacity durability flavor texture" .split ()
1513
1614
@@ -36,7 +34,7 @@ class Day15(aoc.Challenge):
3634 aoc .TestCase (inputs = SAMPLE , part = 2 , want = 57600000 ),
3735 ]
3836
39- def sorted_limits (self , ingredients : InputType , check_calories : bool ) -> int :
37+ def sorted_limits (self , ingredients : dict [ str , dict [ str , int ]], check_calories : bool ) -> list [ tuple [ int , str ]] :
4038 """Generate the acceptable ranges for each ingredient.
4139
4240 The upper limit of ingredients can be computed based on their
@@ -69,13 +67,13 @@ def sorted_limits(self, ingredients: InputType, check_calories: bool) -> int:
6967 limits [name ] = min (limit , limits [name ])
7068 return sorted ((limit , name ) for name , limit in limits .items ())
7169
72- def combo_generator_b (self , ingredients : InputType , check_calories : bool ):
70+ def combo_generator_b (self , ingredients : dict [ str , dict [ str , int ]] , check_calories : bool ):
7371 """Generate amount combinations to try."""
7472 ranges , _ = list (zip (* self .sorted_limits (ingredients , check_calories )))
7573 for amounts in itertools .product (* [range (i + 1 ) for i in ranges [:- 1 ]]):
7674 yield amounts + (100 - sum (amounts ),)
7775
78- def combo_generator (self , ingredients : InputType , check_calories : bool ):
76+ def combo_generator (self , ingredients : dict [ str , dict [ str , int ]] , check_calories : bool ):
7977 """Generate amount combinations to try."""
8078 ranges , _ = list (zip (* self .sorted_limits (ingredients , check_calories )))
8179 num = len (ranges )
@@ -91,7 +89,7 @@ def combo_generator(self, ingredients: InputType, check_calories: bool):
9189 if sum (amounts ) <= 100 :
9290 break
9391
94- def solver (self , puzzle_input : InputType , part_one : bool ) -> int :
92+ def solver (self , puzzle_input : dict [ str , dict [ str , int ]] , part_one : bool ) -> int :
9593 """Solve for the optimal recipe."""
9694 check_calories = not part_one
9795 most = 0
@@ -111,11 +109,10 @@ def solver(self, puzzle_input: InputType, part_one: bool) -> int:
111109 ))
112110 if total == 0 :
113111 continue
114- if total > most :
115- most = total
112+ most = max (total , most )
116113 return most
117114
118- def input_parser (self , puzzle_input : str ) -> InputType :
115+ def input_parser (self , puzzle_input : str ) -> dict [ str , dict [ str , int ]] :
119116 """Parse the input data."""
120117 data = {}
121118 for line in puzzle_input .splitlines ():
0 commit comments