first try for day 2

This commit is contained in:
2023-12-07 20:43:51 +01:00
parent a03d06a062
commit fec2fb31b6
2 changed files with 131 additions and 0 deletions

31
02/02.py Executable file
View File

@@ -0,0 +1,31 @@
#!/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]
game = line.split(":")[1].split(",")
valid = True
for color in game:
temp = color.split(' ')
if 'red' in temp[1]:
if int(temp[0]) > maxred:
valid = False
elif 'green' in temp[1]:
if int(temp[0]) > maxgreen:
valid = False
elif 'blue' in temp[1]:
if int(temp[0]) > maxblue:
valid = False
if not valid:
sol += gameid
print(sol)