Solution to problem 5 part 2 in Python
This commit is contained in:
parent
72b5b21950
commit
5f45fa229b
36
src/P5.py
36
src/P5.py
@ -85,8 +85,44 @@ def part_1() -> None:
|
||||
_col = binary_search(col, 7, "L", "R")
|
||||
_seat_ID: int = _row * 8 + _col
|
||||
seat_ID = max(seat_ID, _seat_ID)
|
||||
|
||||
print(f"The highest seat ID on a boarding pass is {seat_ID}")
|
||||
|
||||
|
||||
# --- Part Two ---
|
||||
|
||||
# Ding! The "fasten seat belt" signs have turned on. Time to find your seat.
|
||||
|
||||
# It's a completely full flight, so your seat should be the only missing
|
||||
# boarding pass in your list. However, there's a catch: some of the seats at
|
||||
# the very front and back of the plane don't exist on this aircraft, so they'll
|
||||
# be missing from your list as well.
|
||||
|
||||
# Your seat wasn't at the very front or back, though; the seats with IDs +1 and
|
||||
# -1 from yours will be in your list.
|
||||
|
||||
# What is the ID of your seat?
|
||||
|
||||
|
||||
def part_2() -> None:
|
||||
seat_IDs: list[int] = []
|
||||
missing_seats: list[int] = []
|
||||
for code in boarding_passes:
|
||||
row, col = code[:7], code[-3:]
|
||||
|
||||
_row = binary_search(row, 127, "F", "B")
|
||||
_col = binary_search(col, 7, "L", "R")
|
||||
_seat_ID: int = _row * 8 + _col
|
||||
seat_IDs.append(_seat_ID)
|
||||
|
||||
for ID in range(len(boarding_passes)):
|
||||
if ID in seat_IDs:
|
||||
pass
|
||||
else:
|
||||
missing_seats.append(ID)
|
||||
print(f"The ID of my seat is {missing_seats[-1]}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
part_1()
|
||||
part_2()
|
||||
|
Loading…
Reference in New Issue
Block a user