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 --- day5/__init__.py | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 day5/__init__.py (limited to 'day5/__init__.py') 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 @@ -from math import ceil, floor -from typing import Iterator, Any - -from aoc import BaseAssignment - - -class Assignment(BaseAssignment): - def parse_item(self, item: str) -> Any: - row = self.calculate_postition(input=item[:7], min=0, max=127) - col = self.calculate_postition(input=item[7:], min=0, max=7) - return (row * 8) + col - - def calculate_postition(self, input: str, min: int, max: int) -> int: - input_length = len(input) - action = input[0] - half = (max - min) / 2 - if action in ['F', 'L']: - return min \ - if input_length == 1 \ - else self.calculate_postition(input[1:], min=min, - max=floor(max - half)) - elif action in ['B', 'R']: - return max \ - if input_length == 1 \ - else self.calculate_postition(input[1:], min=ceil(min + half), - max=max) - - -class AssignmentOne(Assignment): - def run(self, input: Iterator) -> Any: - return max(*input) - - -class AssignmentTwo(Assignment): - def run(self, input: Iterator) -> Any: - seat_ids = sorted(input) - for index, id in enumerate(seat_ids): - next_id = id + 1 - if id + 1 != seat_ids[index + 1]: - return next_id -- cgit v1.2.3