You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
539 B
Python

2 years ago
#!/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)