0
0
Fork 0

Implement the solution for D1P2 in Python

This commit is contained in:
Oliver-Akins 2021-12-29 19:11:51 -07:00
parent 61c7e80d35
commit de2ea7c1df

20
day_01/python/part_2.py Normal file
View file

@ -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}")