Solve day 2

This commit is contained in:
Nettika
2023-12-09 10:09:28 -08:00
parent cfa52e1594
commit c22f0e8eba
6 changed files with 297 additions and 0 deletions

22
02/puzzle.py Normal file
View File

@@ -0,0 +1,22 @@
from game import Game
def solve_pt_1(input: list[str]):
total = 0
for game_desc in input:
game = Game.parse(game_desc)
if game.meets_configuration({"red": 12, "green": 13, "blue": 14}):
total += game.id
return total
def solve_pt_2(input: list[str]):
total = 0
for game_desc in input:
game = Game.parse(game_desc)
total += _configuration_power(game.minimum_configuration())
return total
def _configuration_power(bag: dict[str, int]) -> int:
return bag.get("blue", 0) * bag.get("green", 0) * bag.get("red", 0)