53 lines
976 B
Python
Executable File
53 lines
976 B
Python
Executable File
#!/usr/bin/env python3
|
|
from functools import reduce
|
|
import re, sys
|
|
import sys
|
|
import numpy as np
|
|
|
|
def tpl(l): # get nice tuple from line
|
|
return int(l)
|
|
|
|
def p(*args):
|
|
print(*args)
|
|
|
|
def sum_of_2(l, n):
|
|
d={}
|
|
for i in l:
|
|
for j in l[1:]:
|
|
d[i+j] = True
|
|
try:
|
|
return d[n]
|
|
except:
|
|
return False
|
|
|
|
def good(l):
|
|
return sum_of_2(l[:-1], l[-1])
|
|
|
|
def weak(l, n):
|
|
a = l[0]
|
|
s = a
|
|
for j, b in enumerate(l[1:]):
|
|
s += b
|
|
if s == n:
|
|
return min(l[:j+1]), max(l[:j+1])
|
|
elif s > n:
|
|
break
|
|
|
|
def weakness(l, n):
|
|
for i in range(len(l)):
|
|
w = weak(l[i:], n)
|
|
if w:
|
|
return w
|
|
|
|
fn = sys.argv[1] if len(sys.argv) > 1 else 'input9'
|
|
with open(fn) as f:
|
|
|
|
lines = [l.strip() for l in f.readlines()]
|
|
n = [tpl(l) for l in lines]
|
|
i=0
|
|
while good(n[i:i+26]):
|
|
i += 1
|
|
p(n[i+25])
|
|
p(weakness(n, n[i+25]))
|
|
p(sum(weakness(n, n[i+25])))
|