adventofcode2020/1/1.py

42 lines
745 B
Python
Raw Normal View History

2020-12-02 15:29:10 -05:00
#!/usr/bin/env python3
from random import randrange
import sys
L = []
with open(sys.argv[1], 'r') as f:
L = f.readlines()
L = [int(x.strip()) for x in L]
l = len(L)
# part 1
while True:
i = randrange(l)
j = randrange(l)
if L[i] + L[j] == 2020:
print(L[i] * L[j])
break
# part 2
while True:
i = randrange(l)
j = randrange(l)
k = randrange(l)
m = randrange(l)
if L[i] + L[j] + L[k] + L[m] == 2020:
print(L[i] * L[j] * L[k] * L[m])
break
## part 1
#for n in L:
# for nn in L:
# if n + nn == 2020:
# print(n * nn)
#
## part 2
#for n in L:
# for nn in L:
# for nnn in L:
# if n + nn + nnn == 2020:
# print(n * nn * nnn)