feat: day 2 part 2 done

This commit is contained in:
dqnid committed 2026-08-26 16:31:44 +02:00
1 parent 7d7d41ad2a
commit 279f5c77f5
3 files changed
+28 -4

No files matched your search

+5
View File
@@ -5,3 +5,8 @@ def test_cube_game():
path = r"./src/assets/day_2_test.txt"
game = GameRecord(path)
assert game.sum_valid() == 8
def test_cube_game_power():
path = r"./src/assets/day_2_test.txt"
game = GameRecord(path)
assert game.sum_power() == 2286
+22 -3
View File
@@ -1,11 +1,11 @@
from dataclasses import dataclass
import re
from dataclasses import dataclass
def run():
game = GameRecord(r"./src/assets/day_2.txt")
total_valid = game.sum_valid()
print(f"Total games valid: {total_valid}")
print(f"Total games valid: {game.sum_valid()}")
print(f"Total games power: {game.sum_power()}")
@dataclass
@@ -43,6 +43,25 @@ class GameRecord:
return sum
def sum_power(self):
sum = 0
for game in self.games:
red = 0
green = 0
blue = 0
for play in game.plays:
for item in play:
match item[1]:
case "blue":
blue = max(blue,int(item[0]))
case "red":
red = max(red, int(item[0]))
case "green":
green = max(green,int(item[0]))
sum += red * green * blue
return sum
def read_games(self) -> list[Game]:
with open(self.path) as file: