30 lines
707 B
Plaintext
30 lines
707 B
Plaintext
|
#!/usr/bin/python3
|
||
|
import sys
|
||
|
|
||
|
code = []
|
||
|
with open("input") as fh:
|
||
|
for ln in fh:
|
||
|
code.append(int(ln))
|
||
|
|
||
|
def valid(code, o):
|
||
|
for i in range(o - 25, o - 1):
|
||
|
for j in range(i, o):
|
||
|
if code[i] + code[j] == code[o]:
|
||
|
return True
|
||
|
|
||
|
for o in range(25, len(code)):
|
||
|
if not valid(code, o):
|
||
|
target = code[o]
|
||
|
break
|
||
|
|
||
|
for i in range(len(code)):
|
||
|
for j in range(i + 1, len(code)):
|
||
|
s = sum(code[i:j+1])
|
||
|
if s == target:
|
||
|
smallest = min(code[i:j+1])
|
||
|
largest = max(code[i:j+1])
|
||
|
print(smallest + largest)
|
||
|
sys.exit(0)
|
||
|
elif s > target:
|
||
|
break # adding more numbers won't help
|