# Advent Of Code 2020 Day 9: Cipher (Nut)cracking

For Day 9, the puzzle was
fairly straightforward. Given a list of numbers and a “preamble” size
`n`

, find the first number after the `nth`

number that is not the sum
of two of the previous numbers in the list. This check can be done for
an arbitrary number `s`

like so:

```
def sum_in_window(nums, s):
for num1 in nums:
for num2 in nums:
if num1 + num2 == s:
return True
return False
```

So the first part boils down to:

```
preamble_length = 25
for i in range(preamble_length, len(prog)):
window = prog[i - preamble_length:i]
if not sum_in_window(window, prog[i]):
p1 = prog[i]
break
```

For the second part, the puzzle asks for a contiguous subset of numbers from the list that sum to the number found in part 1, and the sum of the smallest and larget numbers in that subset. This can be done like so:

```
# Iterate through list and keep rolling sum
for i in range(len(prog)):
s = 0
j = i
while s < p1:
s += prog[j]
j += 1
if s == p1:
start = i
end = j
break
p2 = min(prog[start:end]) + max(prog[start:end])
```

I’m sure there are more efficient ways to solve the problem, but I did not find this day’s puzzle particuarly interesting.