diff options
Diffstat (limited to 'day5/__init__.py')
| -rw-r--r-- | day5/__init__.py | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/day5/__init__.py b/day5/__init__.py deleted file mode 100644 index 405b589..0000000 --- a/day5/__init__.py +++ /dev/null | |||
| @@ -1,40 +0,0 @@ | |||
| 1 | from math import ceil, floor | ||
| 2 | from typing import Iterator, Any | ||
| 3 | |||
| 4 | from aoc import BaseAssignment | ||
| 5 | |||
| 6 | |||
| 7 | class Assignment(BaseAssignment): | ||
| 8 | def parse_item(self, item: str) -> Any: | ||
| 9 | row = self.calculate_postition(input=item[:7], min=0, max=127) | ||
| 10 | col = self.calculate_postition(input=item[7:], min=0, max=7) | ||
| 11 | return (row * 8) + col | ||
| 12 | |||
| 13 | def calculate_postition(self, input: str, min: int, max: int) -> int: | ||
| 14 | input_length = len(input) | ||
| 15 | action = input[0] | ||
| 16 | half = (max - min) / 2 | ||
| 17 | if action in ['F', 'L']: | ||
| 18 | return min \ | ||
| 19 | if input_length == 1 \ | ||
| 20 | else self.calculate_postition(input[1:], min=min, | ||
| 21 | max=floor(max - half)) | ||
| 22 | elif action in ['B', 'R']: | ||
| 23 | return max \ | ||
| 24 | if input_length == 1 \ | ||
| 25 | else self.calculate_postition(input[1:], min=ceil(min + half), | ||
| 26 | max=max) | ||
| 27 | |||
| 28 | |||
| 29 | class AssignmentOne(Assignment): | ||
| 30 | def run(self, input: Iterator) -> Any: | ||
| 31 | return max(*input) | ||
| 32 | |||
| 33 | |||
| 34 | class AssignmentTwo(Assignment): | ||
| 35 | def run(self, input: Iterator) -> Any: | ||
| 36 | seat_ids = sorted(input) | ||
| 37 | for index, id in enumerate(seat_ids): | ||
| 38 | next_id = id + 1 | ||
| 39 | if id + 1 != seat_ids[index + 1]: | ||
| 40 | return next_id | ||
