advent/2020/9/solution.py

43 lines
775 B
Python
Raw Normal View History

2021-07-20 12:56:19 -05:00
#!/usr/bin/python
fd = open('input', 'r')
lines = [int(i.rstrip()) for i in fd.readlines()]
data = [int(i) for i in lines[0:24]]
found = 0
cnt = 0
while True:
num = int(lines[25 + cnt])
iicount = 0
for i in data:
for j in data:
if i + j == num: iicount += 1
if iicount == 0:
print(num)
found = num * 10
break
data.append(num)
cnt += 1
found = int(found / 10)
index = lines.index(found)
relevant = lines[0:index]
for i in range(len(relevant)):
added = []
tot = 0
elem = i
try:
while tot != found:
tot += relevant[elem]
added.append(relevant[elem])
elem += 1
added.sort()
print(added[0] + added[-1])
except:
pass