From 4dec21f362c03136e9811a4f4c162fcd8c50544e Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 2 Dec 2021 17:39:03 +0100 Subject: Added day 10 --- day1/__init__.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'day1/__init__.py') diff --git a/day1/__init__.py b/day1/__init__.py index cf48f78..bc44089 100644 --- a/day1/__init__.py +++ b/day1/__init__.py @@ -8,29 +8,23 @@ class Assignment(BaseAssignment): return int(item) def read_input(self, example = False) -> List[int]: - return sorted(super().read_input(example)) + return list(super().read_input(example)) class AssignmentOne(Assignment): def run(self, input: List) -> int: - front_position = 0 - end_position = -1 + result = 0 - while True: - sum = input[front_position] + input[end_position] + for i in range(1, len(input)): + result += 1 if input[i - 1] < input[i] else 0 - if sum > 2020: - end_position -= 1 - elif sum < 2020: - front_position += 1 - else: - break + return result - return input[front_position] * input[end_position] class AssignmentTwo(Assignment): def run(self, input: List) -> int: - for a in input: - for b in input: - for c in input: - if a + b + c == 2020: - return a * b * c \ No newline at end of file + new_input = [ + input[i - 2] + input[i - 1] + input[i] + for i in range(2, len(input)) + ] + + return AssignmentOne(path='').run(new_input) -- cgit v1.2.3