solution for 02p1 and 02p2, also started with 03

This commit is contained in:
2024-01-03 01:53:36 +01:00
parent 06cec4dbc0
commit 02df576daa
4 changed files with 216 additions and 4 deletions

29
02/02p2.py Executable file
View File

@@ -0,0 +1,29 @@
#!/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)