2024-10-24 09:57:31 +02:00

36 lines
873 B
Python
Executable File

#!/usr/bin/env python3
import sys
MAX_RED = 12
MAX_GREEN =13
MAX_BLUE = 14
result = 0
for line in sys.stdin.readlines():
line = line.strip()
game_no, reveals = line.split(': ')
game_no = int(game_no.split()[1])
print(game_no, reveals)
is_game_valid = True
for reveal in reveals.split('; '):
for color in reveal.split(', '):
amount, color = color.split()
if color == 'red' and int(amount) > MAX_RED:
is_game_valid = False
break
if color == 'green' and int(amount) > MAX_GREEN:
is_game_valid = False
break
if color == 'blue' and int(amount) > MAX_BLUE:
is_game_valid = False
break
if not is_game_valid:
break
if is_game_valid:
result += game_no
print(result)