You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
760 B

11 months ago
lines = [i for i in open("input.txt", 'r').read().splitlines()]
sum = 0
11 months ago
sum2 = 0
11 months ago
for l in lines:
sets = [[j.split(" ") for j in i.split(', ')] for i in l.split(": ")[1].split('; ')]
11 months ago
highest = {}
11 months ago
valid = True
for set in sets:
for cubes in set:
cubes[0] = int(cubes[0])
if (cubes[1] == "red" and cubes[0] > 12) or (cubes[1] == "green" and cubes[0] > 13) or (cubes[1] == "blue" and cubes[0] > 14):
valid = False
11 months ago
if cubes[1] not in highest or cubes[0] > highest[cubes[1]]:
highest[cubes[1]] = cubes[0]
11 months ago
if valid:
sum += int(l.split(": ")[0].split(" ")[1])
11 months ago
add = 1
for h in highest:
add *= highest[h]
sum2 += add
11 months ago
11 months ago
print(sum)
print(sum2)