summaryrefslogtreecommitdiffstats
path: root/day5/__init__.py
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <tom@vanderlee.io>2021-12-02 17:39:03 +0100
committerGravatar Tom van der Lee <tom@vanderlee.io>2021-12-02 17:39:03 +0100
commit4dec21f362c03136e9811a4f4c162fcd8c50544e (patch)
treecd90c52c7c936fdbe5fc7f22f3f5bf3240faf9a8 /day5/__init__.py
parent37aa8eec0498d7e8491084711132f16db9129a39 (diff)
download2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.tar.gz
2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.tar.bz2
2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.zip
Added day 10
Diffstat (limited to 'day5/__init__.py')
-rw-r--r--day5/__init__.py40
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 @@
1from math import ceil, floor
2from typing import Iterator, Any
3
4from aoc import BaseAssignment
5
6
7class 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
29class AssignmentOne(Assignment):
30 def run(self, input: Iterator) -> Any:
31 return max(*input)
32
33
34class 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