advent_of_code/2023/2/2_2.py

33 lines
915 B
Python
Raw Normal View History

2023-12-02 16:02:27 +01:00
#!/usr/bin/env python
# 2023 - Advent Of Code 2 - part 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)
power = 1
# pylint: disable=consider-using-dict-items
for c in colors:
power *= colors[c]
print(f'game {game_num} power: {power}')
accum += power
print(f"sum: {accum}")