-
Notifications
You must be signed in to change notification settings - Fork 0
/
d05.py
31 lines (20 loc) · 852 Bytes
/
d05.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from pathlib import Path
from myutils.io_handler import get_input_data
class BinaryBoarding:
def __init__(self, filename):
self.numbers = {
int("".join(["0" if ch in "FL" else "1" for ch in line]), 2)
for line in Path(filename).read_text().splitlines()
}
def maximum_seat_id(self):
return max(self.numbers)
def id_of_my_seat(self):
return (set(range(min(self.numbers), max(self.numbers))) - self.numbers).pop()
if __name__ == "__main__":
data = get_input_data(__file__)
assert BinaryBoarding("sample1.txt").maximum_seat_id() == 357
assert BinaryBoarding("sample2.txt").maximum_seat_id() == 820
print("Tests passed, starting with the puzzle")
puzzle = BinaryBoarding(data.input_file)
print(puzzle.maximum_seat_id())
print(puzzle.id_of_my_seat())