AdventOfCode/2023/day2/part2/part2.py

49 lines
1.3 KiB
Python
Raw Normal View History

2023-12-02 14:21:10 +01:00
#!/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
2023-12-02 14:39:01 +01:00
cubes = []
2023-12-02 14:21:10 +01:00
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)
2023-12-02 14:39:01 +01:00
print()
r = 0
g = 0
b = 0
2023-12-02 14:21:10 +01:00
for idx, i in enumerate(nngame):
2023-12-02 14:39:01 +01:00
if idx != 0: # and imp == False:
#print(i)
2023-12-02 14:21:10 +01:00
for j in i:
2023-12-02 14:39:01 +01:00
#print(j[0], j[1])
2023-12-02 14:21:10 +01:00
for l in range(0,3):
2023-12-02 14:39:01 +01:00
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)
2023-12-02 14:21:10 +01:00
print()
print(count)