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.
36 lines
873 B
Python
36 lines
873 B
Python
1 month ago
|
#!/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)
|