]> git.friedersdorff.com Git - max/advent_of_code_2021.git/blob - 1_2.py
Try day 14
[max/advent_of_code_2021.git] / 1_2.py
1 """Advent day 1, challenge 2
2
3 Count the number of times the input number
4 is higher than the previous one, but do a 3 day sliding window
5 """
6
7 depths = []
8
9 with open("1_1_input.txt") as f:
10     depths = [int(line) for line in f.readlines()]
11
12 sliding_sums = [sum(depths[i:i+3]) for i in range(len(depths) - 2)]
13
14 prev_depth = None
15 n_increased = 0
16 for depth in sliding_sums:
17     if (prev_depth is not None
18             and depth > prev_depth):
19         n_increased += 1
20
21     prev_depth = depth
22
23 print(n_increased)