add: Day2
This commit is contained in:
17
Day2/day2_p1.py
Normal file
17
Day2/day2_p1.py
Normal 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)
|
||||
Reference in New Issue
Block a user