Implement the solution for D1P2 in Python
This commit is contained in:
parent
61c7e80d35
commit
de2ea7c1df
1 changed files with 20 additions and 0 deletions
20
day_01/python/part_2.py
Normal file
20
day_01/python/part_2.py
Normal 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}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue