diff options
Diffstat (limited to '02/main.py')
-rwxr-xr-x | 02/main.py | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -2,13 +2,17 @@ import sys import re -id_sum = 0 +sum = 0 for line in sys.stdin: line = line.strip() game_id, sets = line.split(":") game_id = int(re.sub("[^0-9]", "", game_id)) sets = [x.strip() for x in sets.split(";")] - possible = True + min_cubes = { + "red": 0, + "green": 0, + "blue": 0, + } for set in sets: cubes = [x.strip() for x in set.split(",")] cubes = [{"color": x.split()[1], "count": int(x.split()[0])} for x in cubes] @@ -20,13 +24,11 @@ for line in sys.stdin: for cube in cubes: map[cube["color"]] = cube["count"] - if map["red"] > 12 or map["green"] > 13 or map["blue"] > 14: - possible = False - break - if not possible: - continue + for color in map: + min_cubes[color] = max(min_cubes[color], map[color]) + power = min_cubes["red"] * min_cubes["green"] * min_cubes["blue"] - id_sum += game_id + sum += power -print(f">> {id_sum}") +print(f">> {sum}") |