9
This commit is contained in:
parent
41e7e08bc0
commit
b1d923c72f
2 changed files with 1053 additions and 0 deletions
53
9.py
Normal file
53
9.py
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue