]> git.friedersdorff.com Git - max/advent_of_code_2021.git/commitdiff
finish challenge 2
authorMaximilian Friedersdorff <max@friedersdorff.com>
Sat, 4 Dec 2021 21:46:56 +0000 (21:46 +0000)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Sat, 4 Dec 2021 21:46:56 +0000 (21:46 +0000)
1_2.py [new file with mode: 0644]

diff --git a/1_2.py b/1_2.py
new file mode 100644 (file)
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)