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

33
02/02p1.py Executable file
View File

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