feat: day 2 part 2 done
This commit is contained in:
1 parent
7d7d41ad2a
commit
279f5c77f5
3 files changed
+28
-4
No files matched your search
@@ -7,7 +7,7 @@
|
|||||||
| Day | Name | Part 1 | Part 2 |
|
| Day | Name | Part 1 | Part 2 |
|
||||||
| :-: | :------------------ | :----: | :----: |
|
| :-: | :------------------ | :----: | :----: |
|
||||||
| 1 | | ⭐ | ⭐ |
|
| 1 | | ⭐ | ⭐ |
|
||||||
| 2 | | ⭐ | |
|
| 2 | | ⭐ | ⭐ |
|
||||||
| 3 | | | |
|
| 3 | | | |
|
||||||
| 4 | | | |
|
| 4 | | | |
|
||||||
| 5 | | | |
|
| 5 | | | |
|
||||||
|
|||||||
@@ -5,3 +5,8 @@ def test_cube_game():
|
|||||||
path = r"./src/assets/day_2_test.txt"
|
path = r"./src/assets/day_2_test.txt"
|
||||||
game = GameRecord(path)
|
game = GameRecord(path)
|
||||||
assert game.sum_valid() == 8
|
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
@@ -1,11 +1,11 @@
|
|||||||
from dataclasses import dataclass
|
|
||||||
import re
|
import re
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
game = GameRecord(r"./src/assets/day_2.txt")
|
game = GameRecord(r"./src/assets/day_2.txt")
|
||||||
total_valid = game.sum_valid()
|
print(f"Total games valid: {game.sum_valid()}")
|
||||||
print(f"Total games valid: {total_valid}")
|
print(f"Total games power: {game.sum_power()}")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -43,6 +43,25 @@ class GameRecord:
|
|||||||
|
|
||||||
return sum
|
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]:
|
def read_games(self) -> list[Game]:
|
||||||
with open(self.path) as file:
|
with open(self.path) as file:
|
||||||
|
|||||||
Reference in new issue
Block a user