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] overflow = False 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 > limits[color]: overflow = True break if overflow: break if not overflow: s += int(identifier) print(s)