This commit is contained in:
Sebastian Seedorf
2023-12-05 14:54:55 +01:00
parent 6cdcb4e260
commit afd8903897
3 changed files with 138 additions and 0 deletions

21
day02/part1.py Normal file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env python3
import re
lines = (x.strip() for x in open("input.txt"))
REG_GAME = re.compile("Game (\d+): (.*)$")
MAX_TARGET = {"red": 12, "green": 13, "blue": 14}
total = 0
for line in lines:
game, content = REG_GAME.match(line).groups()
is_possible = True
for cube in (y for x in content.split("; ") for y in x.split(", ")):
[n, color] = cube.split(" ")
if MAX_TARGET[color] < int(n):
is_possible = False
break
if is_possible:
total += int(game)
print(total)