blob: 189d15a8e0ecba7e3006119a379e84311959eb10 (
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
|
import sys
from collections import defaultdict
D = open(sys.argv[1]).read().strip()
p1 = 0
p2 = 0
for line in D.split("\n"):
ok = True
id_, line = line.split(":")
V = defaultdict(int)
for event in line.split(";"):
for balls in event.split(","):
n, colour = balls.split()
n = int(n)
V[colour] = max(V[colour], n)
if int(n) > {"red": 12, "green": 13, "blue": 14}.get(colour, 0):
ok = False
score = 1
for v in V.values():
score *= v
p2 += score
if ok:
p1 += int(id_.split()[-1])
print(p1)
print(p2)
|