diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-12-02 12:49:28 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-12-02 12:49:28 +0100 |
commit | 7ad046492a05b0f3da793d8ab90da021a0afcfc2 (patch) | |
tree | 7f400c0313107b3c0011d0d186e881bd04a03b25 /02 | |
parent | 38b3c013883933a510580b7188a61e1f8d5757ef (diff) |
day two part two
Diffstat (limited to '02')
-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}") |