Add alternative solution for day 1
This commit is contained in:
@@ -25,9 +25,19 @@ def part_2(input):
|
||||
print("Part 2 result:", result)
|
||||
|
||||
|
||||
def alt_solution(input, num_summands):
|
||||
result = 0
|
||||
for i in range(len(input) - num_summands):
|
||||
if int(input[i]) < int(input[i + num_summands]):
|
||||
result += 1
|
||||
print("Alternative result:", result, ", summands =", num_summands)
|
||||
|
||||
|
||||
input = list()
|
||||
with open('input.txt') as fp:
|
||||
input = fp.readlines()
|
||||
|
||||
part_1(input)
|
||||
part_2(input)
|
||||
alt_solution(input, 1)
|
||||
alt_solution(input, 3)
|
||||
|
||||
Reference in New Issue
Block a user