Browse Source

Optimize day 1 a little

master
mid-kid 4 years ago
parent
commit
9c2fc7db77
  1. 37
      d01.py

37
d01.py

@ -1,31 +1,26 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# 99920044 instead of 2020 for bigboy # ./d01.py d01_bigboy.txt 99920044
# p1: 134283487359328 # 1939883877222459
# p2: 1655132197274893972 # 32625808479480099854130
from sys import argv from sys import argv
i = [int(x) for x in open(argv[1])] t = 2020
if len(argv) > 2:
t = int(argv[2])
for x in i: i = set(int(x) for x in open(argv[1]))
def f(x):
for y in i: for y in i:
if x+y == 2020: if x-y in i:
print(x*y) return y*(x-y)
break return None
else: print(f(t))
continue
break
for x in i: for x in i:
for y in i: y = f(t-x)
for z in i: if y:
if x+y+z == 2020: print(x*y)
print(x*y*z)
break
else:
continue
break break
else:
continue
break

Loading…
Cancel
Save