Day 9
This commit is contained in:
1000
day09/input.txt
Normal file
1000
day09/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
16
day09/part1.py
Normal file
16
day09/part1.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from collections import deque
|
||||||
|
from itertools import combinations
|
||||||
|
|
||||||
|
lines = (int(x.strip()) for x in open("input.txt"))
|
||||||
|
L = 25
|
||||||
|
|
||||||
|
buffer = deque(maxlen=L)
|
||||||
|
result = None
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if len(buffer) == L:
|
||||||
|
found = any(a + b == line for a, b in combinations(buffer, 2))
|
||||||
|
if not found:
|
||||||
|
result = line
|
||||||
|
break
|
||||||
|
buffer.append(line)
|
||||||
32
day09/part2.py
Normal file
32
day09/part2.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
from collections import deque
|
||||||
|
from itertools import combinations
|
||||||
|
|
||||||
|
lines = [int(x.strip()) for x in open("input.txt")]
|
||||||
|
L = 25
|
||||||
|
|
||||||
|
buffer = deque(maxlen=L)
|
||||||
|
result = None
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if len(buffer) == L:
|
||||||
|
found = any(a + b == line for a, b in combinations(buffer, 2))
|
||||||
|
if not found:
|
||||||
|
result = line
|
||||||
|
break
|
||||||
|
buffer.append(line)
|
||||||
|
|
||||||
|
if result is None:
|
||||||
|
print("No value found")
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
for start in range(len(lines)):
|
||||||
|
add = 0
|
||||||
|
for end in range(start, len(lines)):
|
||||||
|
add += lines[end]
|
||||||
|
if add == result:
|
||||||
|
mi = min(lines[start:end+1])
|
||||||
|
ma = max(lines[start:end+1])
|
||||||
|
print(mi+ma)
|
||||||
|
exit(0)
|
||||||
|
elif add > result:
|
||||||
|
break
|
||||||
Reference in New Issue
Block a user