Day 2 Part A passed

This commit is contained in:
Ikatono
2023-12-02 04:56:35 -06:00
parent 59dd189da7
commit cf662bd13e
2 changed files with 129 additions and 0 deletions

29
adv02a.py Normal file
View File

@@ -0,0 +1,29 @@
import re
def numpart(s):
return int(''.join(c for c in s if c in '0123456789'))
def game(line):
id_part, cube_part = line.split(':')
id = numpart(id_part)
rounds = cube_part.split(';')
for round in rounds:
cubes = round.split(',')
for cube in cubes:
count = numpart(cube)
if 'blue' in cube:
if count > 14:
return 0
elif 'red' in cube:
if count > 12:
return 0
elif 'green' in cube:
if count > 13:
return 0
return id
with open('adv02a.txt') as f:
txt = f.readlines()
s = sum(game(line) for line in txt)
print(s)