Added day2 part2

This commit is contained in:
FrederikBaerentsen 2023-12-02 14:39:01 +01:00
parent 25d17915cf
commit 28cd15898d

View File

@ -11,7 +11,7 @@ game=[]
count = 0 count = 0
colors= [[12,'red'],[13,'green'],[14,'blue']] colors= [[12,'red'],[13,'green'],[14,'blue']]
imp = False imp = False
cubes = []
with open(input_f) as file: with open(input_f) as file:
for line in file: for line in file:
tmp = line.rstrip().replace(':',';') #read the line tmp = line.rstrip().replace(':',';') #read the line
@ -26,15 +26,23 @@ with open(input_f) as file:
nngame[idx].append(j.split()) nngame[idx].append(j.split())
print("Starting ",end="") print("Starting ",end="")
pprint(nngame) pprint(nngame)
for idx, i in enumerate(nngame):
if idx != 0 and imp == False:
for j in i:
for l in range(0,3):
if j[1] == colors[l][1] and int(j[0]) > colors[l][0] and imp == False:
count = count - int(nngame[0][0][1])
imp = True
count = count + int(nngame[0][0][1])
print("Count is " + str(count) + " and game is " + str(imp))
print() print()
imp = False r = 0
g = 0
b = 0
for idx, i in enumerate(nngame):
if idx != 0: # and imp == False:
#print(i)
for j in i:
#print(j[0], j[1])
for l in range(0,3):
if j[1] == 'red' and int(j[0]) > r:
r = int(j[0])
if j[1] == 'green' and int(j[0]) > g:
g = int(j[0])
if j[1] == 'blue' and int(j[0]) > b:
b = int(j[0])
print('smallest: r:' + str(r) + '. g: ' + str(g) + '. b: ' + str(b))
count = count + (r*g*b)
print()
print(count) print(count)