kuroko/test/day5.krk

78 lines
1.5 KiB
Plaintext

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
def min(iter):
let l # Silly way to get the first value of an iterable that doesn't do []
for v in iter:
l = v
break
for v in iter:
if v < l:
l = v
return l
def max(iter):
let l # Silly way to get the first value of an iterable that doesn't do []
for v in iter:
l = v
break
for v in iter:
if v > l:
l = v
return l
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