Skip to content

Instantly share code, notes, and snippets.

@redspider
Created December 5, 2020 06:57
Show Gist options
  • Save redspider/2583249bf6c90298e83cf2587a9b0955 to your computer and use it in GitHub Desktop.
Save redspider/2583249bf6c90298e83cf2587a9b0955 to your computer and use it in GitHub Desktop.
def partition(start, end, top):
if top:
return start, start + (end - start) // 2
return start + (end - start) // 2 + 1, end
def score_seat(boarding_pass):
start_row = 0
end_row = 127
for c in boarding_pass[:-3]:
start_row, end_row = partition(start_row, end_row, c == 'F')
start_col = 0
end_col = 7
for c in boarding_pass[-3:]:
start_col, end_col = partition(start_col, end_col, c == 'L')
return start_row * 8 + start_col
# part 1
print(max([score_seat(x) for x in INPUT.split("\n")]))
# part 2
used_seats = set([score_seat(x) for x in INPUT.split("\n")])
seats_remaining = set(range(0, 127 * 7)).symmetric_difference(used_seats)
for score in seats_remaining:
if score + 1 not in seats_remaining and score - 1 not in seats_remaining:
print(score)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment