From de2ea7c1df295961fbe55e8a3eb3c4ef7f663d05 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Wed, 29 Dec 2021 19:11:51 -0700 Subject: [PATCH] Implement the solution for D1P2 in Python --- day_01/python/part_2.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 day_01/python/part_2.py diff --git a/day_01/python/part_2.py b/day_01/python/part_2.py new file mode 100644 index 0000000..8c26dfa --- /dev/null +++ b/day_01/python/part_2.py @@ -0,0 +1,20 @@ +increasing = 0 + +with open("../input", "r") as file: + + # parse the text file into an array of integers + data = [int(x) for x in file.read().split("\n")] + + # iterate through the data until we don't have enough data to form a group + # of 3 values + for i in range(0, len(data) - 3): + + # Collect the two values for the ranges for compare + group_1 = sum(data[i : i+3]) + group_2 = sum(data[i+1 : i+4]) + + # check the delta + if group_1 - group_2 < 0: + increasing += 1 + +print(f"Number of groups increasing: {increasing}") \ No newline at end of file