diff options
| author | 2020-12-11 23:53:45 +0100 | |
|---|---|---|
| committer | 2020-12-11 23:53:45 +0100 | |
| commit | 4985ee94450df0bbcf982b7652c946a47707e60c (patch) | |
| tree | 6a19652db8f05ab6546f9b5fe00c7e652f8acd8e /day1/__init__.py | |
| download | 2021-4985ee94450df0bbcf982b7652c946a47707e60c.tar.gz 2021-4985ee94450df0bbcf982b7652c946a47707e60c.tar.bz2 2021-4985ee94450df0bbcf982b7652c946a47707e60c.zip | |
Added AoC day 1 and 2
Diffstat (limited to 'day1/__init__.py')
| -rw-r--r-- | day1/__init__.py | 36 |
1 files changed, 36 insertions, 0 deletions
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 @@ | |||
| 1 | from typing import Iterator, List | ||
| 2 | |||
| 3 | from aoc import AssignmentBase | ||
| 4 | |||
| 5 | |||
| 6 | class Assignment(AssignmentBase): | ||
| 7 | def parse_item(self, item: str) -> int: | ||
| 8 | return int(item) | ||
| 9 | |||
| 10 | def read_input(self, example = False) -> List[int]: | ||
| 11 | return sorted(super().read_input(example)) | ||
| 12 | |||
| 13 | class AssignmentOne(Assignment): | ||
| 14 | def run(self, input: List) -> int: | ||
| 15 | front_position = 0 | ||
| 16 | end_position = -1 | ||
| 17 | |||
| 18 | while True: | ||
| 19 | sum = input[front_position] + input[end_position] | ||
| 20 | |||
| 21 | if sum > 2020: | ||
| 22 | end_position -= 1 | ||
| 23 | elif sum < 2020: | ||
| 24 | front_position += 1 | ||
| 25 | else: | ||
| 26 | break | ||
| 27 | |||
| 28 | return input[front_position] * input[end_position] | ||
| 29 | |||
| 30 | class AssignmentTwo(Assignment): | ||
| 31 | def run(self, input: List) -> int: | ||
| 32 | for a in input: | ||
| 33 | for b in input: | ||
| 34 | for c in input: | ||
| 35 | if a + b + c == 2020: | ||
| 36 | return a * b * c \ No newline at end of file | ||
