-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc2b.py
executable file
·26 lines (23 loc) · 1.04 KB
/
aoc2b.py
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
#!/usr/bin/env python3
INFN = "aoc2a.txt"
with open(INFN) as INF:
sum_powers = 0
for ln, l in enumerate(INF.readlines()):
game_rounds = l.replace("; ", ";").replace(", ", ",").split(": ")[1].split(";")
min_r = 0
min_g = 0
min_b = 0
for gr in game_rounds:
for color_result in gr.strip().split(","):
if color_result.split(" ")[1] == "red":
if int(color_result.split(" ")[0]) > min_r:
min_r = int(color_result.split(" ")[0])
if color_result.split(" ")[1] == "green":
if int(color_result.split(" ")[0]) > min_g:
min_g = int(color_result.split(" ")[0])
if color_result.split(" ")[1] == "blue":
if int(color_result.split(" ")[0]) > min_b:
min_b = int(color_result.split(" ")[0])
print("{} {} {} {} {}".format(min_r * min_g * min_b, min_r, min_g, min_b, l))
sum_powers += min_r * min_g * min_b
print(sum_powers)