Files
AdventOfCode2023/02/02-1.py
2023-12-02 12:18:07 +01:00

34 lines
765 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
RED = 12
GREEN = 13
BLUE = 14
id_sum = 0
input_file = open("input.txt", "r")
for line in input_file:
possible = True
line = line.replace("Game ", "").strip()
line = line.split(":")
game_id = int(line[0])
games = line[1].split(";")
for game in games:
game = game.split(",")
for grab in game:
grab = grab.split()
if grab[1] == "red" and int(grab[0]) > RED:
possible = False
if grab[1] == "green" and int(grab[0]) > GREEN:
possible = False
if grab[1] == "blue" and int(grab[0]) > BLUE:
possible = False
if possible:
id_sum += game_id
print(id_sum)
input_file.close()