Problem

There’s an airplane with 100 seats, and there are 100 ticketed passengers each with an assigned seat. They line up to board in some random order. However, the first person to board is the worst person alive, and just sits in a random seat, without even looking at his boarding pass. Each subsequent passenger sits in his or her own assigned seat if it’s empty, but sits in a random open seat if the assigned seat is occupied. What is the probability that you, the hundredth passenger to board, finds your seat unoccupied?

Solution

from random import sample

runs = 10000
num_seats = 100
cnt_success = 0
for _ in range(runs):
seats = set(range(num_seats))
first_seat = sample(seats, 1)[0]
seats.remove(first_seat)
for i in range(1, num_seats-1):
if i in seats:
seats.remove(i)
else:
seat = sample(seats, 1)[0]
seats.remove(seat)
if num_seats-1 in seats:
cnt_success += 1
print(cnt_success/runs)

The probability of the hundredth passenger finding his or her seat unoccupied is $0.5$. This probability is independent of the number of seats/passengers.