first try for day 2
This commit is contained in:
31
02/02.py
Executable file
31
02/02.py
Executable 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)
|
Reference in New Issue
Block a user