blob: 4d5cdbfe92203aaf65cf1eb05bb18103ad1abf46 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#!/bin/python3
import sys
import re
sum = 0
for line in sys.stdin:
line = line.strip()
game_id, sets = line.split(":")
game_id = int(re.sub("[^0-9]", "", game_id))
sets = [x.strip() for x in sets.split(";")]
min_cubes = {
"red": 0,
"green": 0,
"blue": 0,
}
for set in sets:
cubes = [x.strip() for x in set.split(",")]
cubes = [{"color": x.split()[1], "count": int(x.split()[0])} for x in cubes]
map = {
"red": 0,
"green": 0,
"blue": 0,
}
for cube in cubes:
map[cube["color"]] = cube["count"]
for color in map:
min_cubes[color] = max(min_cubes[color], map[color])
power = min_cubes["red"] * min_cubes["green"] * min_cubes["blue"]
sum += power
print(f">> {sum}")
|