AdventOfCode/2023/day2/part2/part2.py

41 lines
1.1 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
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)
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
print(count)