From b4fed13abe1b3438a7ab4bba762b47aecd85cd56 Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Sat, 4 Dec 2021 21:46:56 +0000 Subject: [PATCH] finish challenge 2 --- 1_2.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 1_2.py 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) -- 2.47.1