Files
AdventOfCode2023/02/02p2.py

30 lines
818 B
Python
Executable File

#!/usr/bin/python
inputfile = open("input.txt", "r")
lines = inputfile.readlines()
sol = 0
for line in lines:
line = line.replace('\n', "")
gameid = line.split(":")[0].split(" ")[1]
games = line.split(":")[1].split(";")
maxred = 0
maxgreen = 0
maxblue = 0
for pull in games:
colors = pull.split(',')
for color in colors:
temp = color.split(' ')
if 'red' in temp[2]:
if int(temp[1]) > maxred:
maxred = int(temp[1])
elif 'green' in temp[2]:
if int(temp[1]) > maxgreen:
maxgreen = int(temp[1])
elif 'blue' in temp[2]:
if int(temp[1]) > maxblue:
maxblue = int(temp[1])
sol += maxred * maxgreen * maxblue
print(sol)