54 lines
1.1 KiB
Python
54 lines
1.1 KiB
Python
|
import itertools
|
||
|
|
||
|
prev=None
|
||
|
sums = dict()
|
||
|
ns = []
|
||
|
with open("9.txt") as f:
|
||
|
for i in range(25):
|
||
|
ns.append(int(f.readline().strip()))
|
||
|
for a in ns:
|
||
|
for b in ns:
|
||
|
if a == b: continue
|
||
|
if a not in sums: sums[a] = set()
|
||
|
sums[a].add(a + b)
|
||
|
|
||
|
for line in f:
|
||
|
n = int(line.strip())
|
||
|
for v in sums.values():
|
||
|
if n in v:
|
||
|
break
|
||
|
else:
|
||
|
print("NOT", n)
|
||
|
bad = n
|
||
|
break
|
||
|
fi = ns[0]
|
||
|
del sums[fi]
|
||
|
ns.pop(0)
|
||
|
sums[n] = set()
|
||
|
for a in ns:
|
||
|
sums[n].add(a + n)
|
||
|
ns.append(n)
|
||
|
|
||
|
|
||
|
with open("9.txt") as f:
|
||
|
ns = []
|
||
|
for line in f:
|
||
|
n = int(line.strip())
|
||
|
ns.append(n)
|
||
|
|
||
|
for a in range(len(ns)-1):
|
||
|
running = ns[a]
|
||
|
found = False
|
||
|
for b in range(a+1, len(ns)):
|
||
|
running+=ns[b]
|
||
|
if running==bad:
|
||
|
r = ns[a:b+1]
|
||
|
print(bad, sum(r), min(r)+max(r), r)
|
||
|
found = True
|
||
|
elif running > bad:
|
||
|
break
|
||
|
#print(a, running, ns[a:b])
|
||
|
if found: break
|
||
|
|
||
|
|