add: Day2

This commit is contained in:
2023-12-02 11:53:59 +01:00
parent b7fe041a21
commit 104706e2ba
3 changed files with 135 additions and 0 deletions

17
Day2/day2_p1.py Normal file
View File

@@ -0,0 +1,17 @@
f = open("input", "r")
CUBES = {"red": 12, "green": 13, "blue": 14}
tot = 0
for line in f.readlines() :
curr_id = int(line.split(':')[0][5:])
l = line.split(f"Game {curr_id}:")[1]
sets = l.split(';')
tmp = 1
for s in sets :
vals = s.split(',')
for c in vals :
c = c[1:].replace('\n', '')
if int(c.split(' ')[0]) > CUBES[c.split(' ')[1]] :
tmp = 0
if tmp == 1 :
tot += curr_id
print(tot)