35 lines
971 B
Python
35 lines
971 B
Python
|
#!/usr/bin/env python
|
||
|
# 2023 - Advent Of Code 2
|
||
|
|
||
|
# file = 'input_example.txt'
|
||
|
file = 'input.txt'
|
||
|
|
||
|
maxb = {'red': 12, 'green': 13, 'blue': 14}
|
||
|
|
||
|
# pylint: disable=consider-using-with
|
||
|
input_lines = [line.strip('\n') for line in open(file, encoding="utf-8")]
|
||
|
accum = 0
|
||
|
for line in input_lines:
|
||
|
impossible = False
|
||
|
games_list = line.split(':')
|
||
|
game_num = int(games_list[0][4:])
|
||
|
# print(f"{game_num}")
|
||
|
colors = {'red': 0, 'green': 0, 'blue': 0}
|
||
|
for game in games_list[1].split(';'):
|
||
|
for ball in game.split(','):
|
||
|
(space, num, color) = ball.split(' ')
|
||
|
# print(f'{num} {color}')
|
||
|
if int(num) > colors[color]:
|
||
|
colors[color] = int(num)
|
||
|
|
||
|
# pylint: disable=consider-using-dict-items
|
||
|
for c in colors:
|
||
|
if colors[c] > maxb[c]:
|
||
|
impossible = True
|
||
|
|
||
|
if not impossible:
|
||
|
print(f'game {game_num} counted')
|
||
|
accum += game_num
|
||
|
|
||
|
print(f"sum: {accum}")
|