add solution 9, parts 1 and 2

This commit is contained in:
randomuser 2021-07-20 12:56:19 -05:00
parent 34d996c2c1
commit baa82e4fa0
2 changed files with 1042 additions and 0 deletions

1000
2020/9/input Normal file

File diff suppressed because it is too large Load Diff

42
2020/9/solution.py Normal file
View File

@ -0,0 +1,42 @@
#!/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