Day 02
This commit is contained in:
17
day02/part2.py
Normal file
17
day02/part2.py
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
import re
|
||||
|
||||
lines = (x.strip() for x in open("input.txt"))
|
||||
|
||||
REG_GAME = re.compile("Game (\d+): (.*)$")
|
||||
total = 0
|
||||
|
||||
for line in lines:
|
||||
game, content = REG_GAME.match(line).groups()
|
||||
cubes = {"red": 0, "green": 0, "blue": 0}
|
||||
for cube in (y for x in content.split("; ") for y in x.split(", ")):
|
||||
[n, color] = cube.split(" ")
|
||||
cubes[color] = max(cubes[color], int(n))
|
||||
total += cubes["red"] * cubes["green"] * cubes["blue"]
|
||||
|
||||
print(total)
|
||||
Reference in New Issue
Block a user