AdventOfCode/2023/day2/part2/part2.py

49 lines
1.3 KiB
Python

#!/bin/python3
import re
import sys
import numpy as np
from pprint import pprint
input_f = sys.argv[1]
count = 0
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
game = tmp.split(';')
ngame = []
nngame = []
for i in game:
ngame.append(i.lstrip().split(', '))
for idx,i in enumerate(ngame):
nngame.append([])
for j in i:
nngame[idx].append(j.split())
print("Starting ",end="")
pprint(nngame)
print()
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)