-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday5_part2.py
39 lines (27 loc) · 957 Bytes
/
day5_part2.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
from math import floor, ceil
with open('input5.txt', 'r') as file:
puzzle = file.read().strip().splitlines()
plane = {}
def seat_id(seat):
rows = (0, 127)
while seat[0] in ('F', 'B'):
if seat[0] == 'F':
rows = (rows[0], floor((rows[0] + rows[1]) / 2))
elif seat[0] == 'B':
rows = (ceil((rows[0] + rows[1]) / 2), rows[1])
seat = seat[1:]
columns = (0, 8)
while seat != '':
if seat[0] == 'L':
columns = (columns[0], floor((columns[0] + columns[1]) / 2))
elif seat[0] == 'R':
columns = (ceil((columns[0] + columns[1]) / 2), columns[1])
seat = seat[1:]
return rows[0] * 8 + columns[0]
for seat in puzzle:
plane[seat_id(seat)] = True
for x in range(8):
for y in range(1, 127):
sid = y * 8 + x
if sid not in plane and (sid + 1) in plane and (sid - 1) in plane:
print(sid)