From 4985ee94450df0bbcf982b7652c946a47707e60c Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Fri, 11 Dec 2020 23:53:45 +0100 Subject: Added AoC day 1 and 2 --- day1/__init__.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 day1/__init__.py (limited to 'day1/__init__.py') diff --git a/day1/__init__.py b/day1/__init__.py new file mode 100644 index 0000000..ce728cc --- /dev/null +++ b/day1/__init__.py @@ -0,0 +1,36 @@ +from typing import Iterator, List + +from aoc import AssignmentBase + + +class Assignment(AssignmentBase): + def parse_item(self, item: str) -> int: + return int(item) + + def read_input(self, example = False) -> List[int]: + return sorted(super().read_input(example)) + +class AssignmentOne(Assignment): + def run(self, input: List) -> int: + front_position = 0 + end_position = -1 + + while True: + sum = input[front_position] + input[end_position] + + if sum > 2020: + end_position -= 1 + elif sum < 2020: + front_position += 1 + else: + break + + 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 -- cgit v1.2.3