part 1 day 02

This commit is contained in:
starnakin 2023-12-02 12:49:51 +01:00
parent b0326283f2
commit a93f6e64e5
2 changed files with 25 additions and 0 deletions

5
2023/day02/example.txt Normal file
View File

@ -0,0 +1,5 @@
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green

20
2023/day02/src/part1.py Normal file
View File

@ -0,0 +1,20 @@
text: str = open("input.txt", "r").read()
bozo_dict: dict = {
"red": 12,
"green": 13,
"blue": 14,
}
value: int = 0
for line in text.split("\n"):
ok = 0
game = line.split(": ")
for bozo_set in game[1].split("; "):
for cube in bozo_set.split(", "):
values = cube.split(" ")
ok += int(values[0]) > bozo_dict.get(values[1])
value = value + int(game[0][5:]) * (ok == 0)
print(value)