This commit is contained in:
2023-12-02 12:18:07 +01:00
parent ea99b85b35
commit b0015c71e9
8 changed files with 600 additions and 11 deletions

33
02/02-1.py Normal file
View File

@@ -0,0 +1,33 @@
#!/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()