aoc2023/d02/part1.py

25 lines
580 B
Python
Raw Permalink Normal View History

2023-12-02 12:22:44 +00:00
import sys
m_red=12
m_green =13
m_blue = 14
R = 0
for i,l in enumerate(sys.stdin.readlines()):
_, l = l[:-1].split(':')
tirages = l.split(';')
possible = True
for tirage in tirages:
cubes = tirage.split(',')
for cube in cubes:
_, q, c = cube.split(' ')
q = int(q)
if c == 'red' and q>m_red:
possible = False
if c == 'green' and q>m_green:
possible = False
if c == 'blue' and q>m_blue:
possible = False
R += possible * (i+1)
print(R)