From: Maximilian Friedersdorff Date: Sat, 4 Dec 2021 21:46:56 +0000 (+0000) Subject: finish challenge 2 X-Git-Url: https://git.friedersdorff.com/?a=commitdiff_plain;h=b4fed13abe1b3438a7ab4bba762b47aecd85cd56;p=max%2Fadvent_of_code_2021.git finish challenge 2 --- diff --git a/1_2.py b/1_2.py new file mode 100644 index 0000000..d08eb0b --- /dev/null +++ b/1_2.py @@ -0,0 +1,23 @@ +"""Advent day 1, challenge 2 + +Count the number of times the input number +is higher than the previous one, but do a 3 day sliding window +""" + +depths = [] + +with open("1_1_input.txt") as f: + depths = [int(line) for line in f.readlines()] + +sliding_sums = [sum(depths[i:i+3]) for i in range(len(depths) - 2)] + +prev_depth = None +n_increased = 0 +for depth in sliding_sums: + if (prev_depth is not None + and depth > prev_depth): + n_increased += 1 + + prev_depth = depth + +print(n_increased)