advent_of_code/2021/1/1_2.py

24 lines
543 B
Python
Raw Normal View History

2021-12-06 01:27:38 +01:00
#!/usr/bin/env python
# 2021 - Advent Of Code 1 - part 2
count = 0
2022-04-05 13:27:24 +02:00
with open('input.txt', encoding="utf-8") as f:
2021-12-06 01:27:38 +01:00
n2_value = int(f.readline())
n1_value = int(f.readline())
n_value = int(f.readline())
previous_sum = n2_value + n1_value + n_value
for line in f:
n2_value = n1_value
n1_value = n_value
n_value = int(line)
current_sum = n2_value + n1_value + n_value
if current_sum > previous_sum:
count += 1
previous_sum = current_sum
print(f'count: {count}')