58 lines
1.1 KiB
Python
58 lines
1.1 KiB
Python
from fileio import open
|
|
|
|
let f = open('test/day5.in')
|
|
let lines = f.read().split('\n')[:-1]
|
|
|
|
def process_row(seat):
|
|
let bottom = 0
|
|
let top = 128
|
|
let size = 128
|
|
for c in seat[:7]:
|
|
if c == 'F':
|
|
top -= size // 2
|
|
else if c == 'B':
|
|
bottom += size // 2
|
|
size = size // 2
|
|
return bottom
|
|
|
|
def process_seat(seat):
|
|
let bottom = 0
|
|
let top = 8
|
|
let size = 8
|
|
for c in seat[7:]:
|
|
if c == 'L':
|
|
top -= size // 2
|
|
else if c == 'R':
|
|
bottom += size // 2
|
|
size = size // 2
|
|
return bottom
|
|
|
|
print(process_row("FBFBBFFRLR")) # 44
|
|
print(process_seat("FBFBBFFRLR")) # 5
|
|
|
|
def seat_id(seat):
|
|
let row = process_row(seat)
|
|
seat = process_seat(seat)
|
|
return row * 8 + seat
|
|
|
|
let top = -1
|
|
for l in lines:
|
|
let i = seat_id(l)
|
|
if i > top:
|
|
top = i
|
|
|
|
print(top) # Answer to part 1, should be 953
|
|
|
|
let taken = {}
|
|
|
|
for l in lines:
|
|
let i = seat_id(l)
|
|
taken[i] = 1
|
|
|
|
print("---")
|
|
for i in range(min(taken.keys()), max(taken.keys())):
|
|
if (i - 1) in taken and (i + 1) in taken and i not in taken:
|
|
print(i)
|
|
|
|
# Should print once, 615
|