import numpy as np with open("data/input.txt", "r") as f: games = f.read() limits = { "red": 12, "green": 13, "blue": 14 } s = 0 for game in games.split("\n")[:-1]: parts = game.split(":") head = parts[0] identifier = head.split(" ")[1] max_counts = dict(red=0, green=0, blue=0) for draw in parts[1].split(";"): draw = draw.strip() for count in draw.split(","): count = count.strip() count_parts = count.split(" ") color = count_parts[1] amount = int(count_parts[0]) if amount > max_counts[color]: max_counts[color] = amount s += np.prod(list(max_counts.values())) print(s)