-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
43 lines (31 loc) · 1.01 KB
/
script.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from math import prod
from GhostyUtils import aoc
if __name__ == '__main__':
inputs = aoc.read_lines()
bag = {'red': 12, 'green': 13, 'blue': 14}
possible_games = []
powers = []
for game in inputs:
cols = {'red': 0, 'green': 0, 'blue': 0}
skip = False
g = game.split(': ')
game_id = int(g[0].split(' ')[1])
rounds = g[1].split('; ')
# print(game, '->', game_id, rounds)
for game_round in rounds:
cubes = game_round.split(', ')
for cube in cubes:
cube = cube.split(' ')
num_cubes = int(cube[0])
colour = cube[1]
if cols[colour] < num_cubes:
cols[colour] = num_cubes
for c, n in cols.items():
if n > bag[c]:
skip = True
break
powers.append(prod(cols.values()))
if not skip:
possible_games.append(game_id)
print(sum(possible_games))
print(sum(powers))