adventofcode-2023/02/part01.py

41 lines
654 B
Python
Raw Normal View History

2023-12-04 22:06:10 +01:00
#!/usr/bin/env python
from sys import stdin
import re
def read_line():
for line in stdin:
yield line
sum = 0
for line in read_line():
t1 = line.split(":", 2)
num = int(t1[0].split(" ")[-1])
rounds = t1[1].split(";")
correct = True
for round in rounds:
red = 0
green = 0
blue = 0
m = re.search("(\d+) blue", round)
if m:
blue = int(m.group(1))
m = re.search("(\d+) red", round)
if m:
red = int(m.group(1))
m = re.search("(\d+) green", round)
if m:
green = int(m.group(1))
if red > 12:
correct = False
if green > 13:
correct = False
if blue > 14:
correct = False
if correct:
sum += num
print(sum)