parent
7d30023c33
commit
b96edf7ad8
1 changed files with 10 additions and 1 deletions
@ -1,16 +1,25 @@ |
|||||||
lines = [i for i in open("input.txt", 'r').read().splitlines()] |
lines = [i for i in open("input.txt", 'r').read().splitlines()] |
||||||
|
|
||||||
sum = 0 |
sum = 0 |
||||||
|
sum2 = 0 |
||||||
|
|
||||||
for l in lines: |
for l in lines: |
||||||
sets = [[j.split(" ") for j in i.split(', ')] for i in l.split(": ")[1].split('; ')] |
sets = [[j.split(" ") for j in i.split(', ')] for i in l.split(": ")[1].split('; ')] |
||||||
|
highest = {} |
||||||
valid = True |
valid = True |
||||||
for set in sets: |
for set in sets: |
||||||
for cubes in set: |
for cubes in set: |
||||||
cubes[0] = int(cubes[0]) |
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): |
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 |
valid = False |
||||||
|
if cubes[1] not in highest or cubes[0] > highest[cubes[1]]: |
||||||
|
highest[cubes[1]] = cubes[0] |
||||||
if valid: |
if valid: |
||||||
sum += int(l.split(": ")[0].split(" ")[1]) |
sum += int(l.split(": ")[0].split(" ")[1]) |
||||||
|
add = 1 |
||||||
|
for h in highest: |
||||||
|
add *= highest[h] |
||||||
|
sum2 += add |
||||||
|
|
||||||
print(sum) |
print(sum) |
||||||
|
print(sum2) |
Loading…
Reference in new issue