2020-12-09 13:25:32 +01:00
|
|
|
import itertools
|
2020-12-10 22:43:00 +01:00
|
|
|
import sys
|
2020-12-09 13:25:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2020-12-10 22:43:00 +01:00
|
|
|
series = [int(line.rstrip()) for line in sys.stdin]
|
2020-12-09 13:25:32 +01:00
|
|
|
|
|
|
|
# Part 1
|
|
|
|
frame_len = 25
|
|
|
|
for i in range(len(series) - frame_len):
|
|
|
|
frame = series[i : i + frame_len]
|
|
|
|
n = series[i + frame_len]
|
|
|
|
for a, b in itertools.combinations(frame, 2):
|
|
|
|
if a + b == n:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
print("Invalid N:", n)
|
|
|
|
break
|
|
|
|
|
|
|
|
# Part 2
|
|
|
|
for i in range(len(series)): # what is indexerror when you know it breaks
|
|
|
|
for j in range(1, len(series)):
|
|
|
|
frame = series[i : i + j + 1]
|
|
|
|
if (s := sum(frame)) == n:
|
|
|
|
print("Answer:", min(frame) + max(frame))
|
|
|
|
return
|
|
|
|
elif s > n:
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|