You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
835 B
Python

#!/usr/bin/env python3
import sys
result = 0
for line in sys.stdin.readlines():
line = line.strip()
game_no, reveals = line.split(': ')
game_no = int(game_no.split()[1])
is_game_valid = True
min_red = 0
min_green = 0
min_blue = 0
for reveal in reveals.split('; '):
for color in reveal.split(', '):
amount, color = color.split()
amount = int(amount)
if color == 'red' and amount > min_red:
min_red = amount
if color == 'green' and amount > min_green:
min_green = amount
if color == 'blue' and amount > min_blue:
min_blue = amount
power = min_red * min_green * min_blue
print(f'{game_no}: {min_red=} {min_blue=} {min_green=} {power=}')
result += power
print(result)