diff --git a/2023/day2/part2/part2.py b/2023/day2/part2/part2.py index b4eb8fd..b9da8f9 100644 --- a/2023/day2/part2/part2.py +++ b/2023/day2/part2/part2.py @@ -11,7 +11,7 @@ game=[] count = 0 colors= [[12,'red'],[13,'green'],[14,'blue']] imp = False - +cubes = [] with open(input_f) as file: for line in file: tmp = line.rstrip().replace(':',';') #read the line @@ -26,15 +26,23 @@ with open(input_f) as file: nngame[idx].append(j.split()) print("Starting ",end="") 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() - 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)