kuroko/test/day5.krk

58 lines
1.1 KiB
Python
Raw Normal View History

2021-01-04 14:10:39 +03:00
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':
2021-04-02 09:33:33 +03:00
top -= size // 2
2021-01-04 14:10:39 +03:00
else if c == 'B':
2021-04-02 09:33:33 +03:00
bottom += size // 2
size = size // 2
2021-01-04 14:10:39 +03:00
return bottom
def process_seat(seat):
let bottom = 0
let top = 8
let size = 8
for c in seat[7:]:
if c == 'L':
2021-04-02 09:33:33 +03:00
top -= size // 2
2021-01-04 14:10:39 +03:00
else if c == 'R':
2021-04-02 09:33:33 +03:00
bottom += size // 2
size = size // 2
2021-01-04 14:10:39 +03:00
return bottom
print(process_row("FBFBBFFRLR")) # 44
print(process_seat("FBFBBFFRLR")) # 5
2021-01-04 14:10:39 +03:00
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
2021-01-04 14:10:39 +03:00
let taken = {}
for l in lines:
let i = seat_id(l)
taken[i] = 1
print("---")
2021-01-04 14:10:39 +03:00
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)
2021-01-04 14:10:39 +03:00
# Should print once, 615