Browse Source

Small optimization

master
mid-kid 1 year ago
parent
commit
569b2b6f05
  1. 2
      d02.py

2
d02.py

@ -2,5 +2,5 @@
from sys import argv
inp = {int(x.split()[1]): [{a.split()[1]: int(a.split()[0]) for a in z.split(",")} for z in y.split(";")] for x, y in map(lambda x: x.split(":"), open(argv[1]).readlines())}
print(sum([x for x, y in inp.items() if all([z.get("red", 0) <= 12 and z.get("green", 0) <= 13 and z.get("blue", 0) <= 14 for z in y])]))
print(sum(x for x, y in inp.items() if all(z.get("red", 0) <= 12 and z.get("green", 0) <= 13 and z.get("blue", 0) <= 14 for z in y)))
print(sum(max(map(lambda x: x.get("red", 0), y)) * max(map(lambda x: x.get("green", 0), y)) * max(map(lambda x: x.get("blue", 0), y)) for x, y in inp.items()))

Loading…
Cancel
Save