adventofcode/2021/1/2.py
2022-12-01 21:13:55 +01:00

25 lines
539 B
Python
Executable File

#!/usr/bin/env python3
content = open('input', 'r').readlines()
depth_inc = 0
last_window = 9999
window = [] # queue for "search window"
window_size = 3
while len(window) < window_size:
window.append(int(content.pop(0).strip()))
# we now have our starting state
last_window = sum(window)
while(content):
# slide window 1 position
window.pop(0)
window.append(int(content.pop(0).strip()))
window_sum = sum(window)
if window_sum > last_window:
depth_inc += 1
last_window = window_sum
print(depth_inc)