-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday5.py
executable file
·39 lines (29 loc) · 1015 Bytes
/
day5.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
32
33
34
35
36
37
38
39
class BoardingPass:
def __init__(self, code: str):
self._row_code = code[:-3]
self._col_code = code[-3:]
self._translation = str.maketrans('LRBF', '0110')
self._row = int(self._row_code.translate(self._translation), 2)
self._col = int(self._col_code.translate(self._translation), 2)
@property
def ID(self) -> int:
return self._row * 8 + self._col
with open('test.txt', 'r') as f:
boarding_passes = f.readlines()
def solve_part1():
vip = 0
for bp in boarding_passes:
ticket = BoardingPass(bp.strip())
if ticket.ID > vip:
vip = ticket.ID
print(vip)
def solve_part2():
available_seats = []
for bp in boarding_passes:
ticket = BoardingPass(bp.strip())
available_seats.append(ticket.ID)
available_seats = sorted(available_seats)
print(set(range(available_seats[0], available_seats[-1])) - set(available_seats))
if __name__ == '__main__':
solve_part1()
solve_part2()