diff options
| author | 2021-12-07 16:06:04 +0100 | |
|---|---|---|
| committer | 2021-12-07 16:06:04 +0100 | |
| commit | b2c17ba9c350dd52688c1eee910c801b794e2ea7 (patch) | |
| tree | 55741ce98c60e851ac242d7a0eca8bd139cc9187 /day7/__init__.py | |
| parent | 906fc128a0f99fec656901f55055ef78e10693b4 (diff) | |
| download | 2021-b2c17ba9c350dd52688c1eee910c801b794e2ea7.tar.gz 2021-b2c17ba9c350dd52688c1eee910c801b794e2ea7.tar.bz2 2021-b2c17ba9c350dd52688c1eee910c801b794e2ea7.zip | |
Day 7: Slow
Diffstat (limited to 'day7/__init__.py')
| -rw-r--r-- | day7/__init__.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/day7/__init__.py b/day7/__init__.py new file mode 100644 index 0000000..b3579b7 --- /dev/null +++ b/day7/__init__.py | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | from collections import Counter | ||
| 2 | from copy import copy | ||
| 3 | from typing import List | ||
| 4 | |||
| 5 | from aoc import BaseAssignment | ||
| 6 | |||
| 7 | class Assignment(BaseAssignment): | ||
| 8 | def parse_item(self, item: str) -> List[int]: | ||
| 9 | return [ int(i) for i in item.split(',') ] | ||
| 10 | |||
| 11 | def read_input(self, example = False) -> List[int]: | ||
| 12 | return next(super().read_input(example)) | ||
| 13 | |||
| 14 | @staticmethod | ||
| 15 | def calculate_cost(start, end) -> int: | ||
| 16 | raise NotImplementedError() | ||
| 17 | |||
| 18 | def run(self, input: List[int]) -> int: | ||
| 19 | return min([ | ||
| 20 | sum([ | ||
| 21 | self.calculate_cost(item, position) | ||
| 22 | for item in input | ||
| 23 | ]) | ||
| 24 | for position in range(min(input), max(input) + 1) | ||
| 25 | ]) | ||
| 26 | |||
| 27 | class AssignmentOne(Assignment): | ||
| 28 | example_result = 37 | ||
| 29 | |||
| 30 | @staticmethod | ||
| 31 | def calculate_cost(start, end) -> int: | ||
| 32 | return abs(end - start) | ||
| 33 | |||
| 34 | class AssignmentTwo(Assignment): | ||
| 35 | example_result = 168 | ||
| 36 | |||
| 37 | @staticmethod | ||
| 38 | def calculate_cost(start, end) -> int: | ||
| 39 | base_cost = AssignmentOne.calculate_cost(start, end) | ||
| 40 | extra = sum(i for i in range(base_cost)) | ||
| 41 | return base_cost + extra \ No newline at end of file | ||
