2023/day2/part1.py
Fedaya fbf1c66a39 Nouveau Repository
Je perd l'historique, mais ne stocke plus les fichiers input.txt
entre autre choses
2023-12-02 12:45:07 +01:00

21 lines
661 B
Python
Executable File

#!/usr/bin/env python3.11
import re
maximums = { 'red': 12, 'green': 13, 'blue': 14}
def game_turn(game_id:int, data: str) -> int:
sets = data.split('; ')
for dset in sets:
cubes = dset.split(', ')
for cube in cubes:
print(cube.split(' '))
number, color = cube.split(' ')
number = int(number)
if number > maximums[color]:
return 0
return game_id
id_sum = 0
with open('input.txt', 'r') as input:
while line := input.readline():
match = re.match("Game (\d+): (.*)", line)
id_sum += game_turn(int(match.groups(0)[0]), match.groups(0)[1])
print(id_sum)