From 47606c7dbfa4d0ba5f29897d22e91f89b521af93 Mon Sep 17 00:00:00 2001 From: Pascal Lais Date: Wed, 1 Dec 2021 18:34:21 +0100 Subject: [PATCH] Add alternative solution for day 1 --- day-01/day-01.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/day-01/day-01.py b/day-01/day-01.py index 8aa1aa7..707c57b 100644 --- a/day-01/day-01.py +++ b/day-01/day-01.py @@ -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)