r/backtickbot • u/backtickbot • Dec 05 '20
https://np.reddit.com/r/adventofcode/comments/k71h6r/2020_day_05_solutions/geqrfef/
Python Solution
with open("adventofcode/2020/day5") as input:
lines = input.readlines()
max_id = 0
seats = []
for test in lines:
row = 0
row_low = 0
row_mid = 0
row_high = 127
col = 0
col_low = 0
col_mid = 0
col_high = 7
for letter in test:
if letter == "F":
row_mid = (row_high+row_low)//2
row_high = row_mid
if letter == "B":
row_mid = (row_high+row_low)//2
row_low = row_mid
if letter == "R":
col_mid = (col_high+col_low)//2
col_low = col_mid
if letter == "L":
col_mid = (col_high+col_low)//2
col_high = col_mid
seat_id = (row_low+1)*8+col_high
max_id = max(seat_id, max_id)
seats.append(seat_id)
print(max_id)
# part 2
#print(sorted(seats))
sorted_seats = sorted(seats)
for i in range(1, len(seats)-1):
if sorted_seats[i+1] != sorted_seats[i] + 1:
print(sorted_seats[i]+1)
1
Upvotes