Can you help me solve this puzzle I received in an online quiz as part of a job application? I only had about 4 minutes to solve it.
There are 2016 passengers about to board a plane, numbered 1 through 2016 in that order. Each passenger is assigned to the seat equal to his or her own number. However, the first passenger disregards instructions and instead of sitting in seat number 1, chooses and sits down in a randomly chosen seat. Each subsequent passenger acts according to the following scheme: if their assigned seat is available, they will sit there; otherwise, they will pick at random from the remaining available seats and sit there. What is the probability that the 1512th passenger ends up sitting in their assigned seat?
A. 1 / 2016
B. 1 / 2
C. 5 / 8
D. 3 / 4
E. None of the above
The idea is to solve the problem using a pen, paper and a calculator. However, I had no idea of the solution during the 4 minutes I was given. I now think the answer is none of the above.
I have written a Monte Carlo simulation in Python (see below) that suggests the answer is >99%. Here is the python code:
import random
import time
tic = time.time()
N = 2016
n = 1512
def simulate_seat_choosing(N, n):
available_seats = [i for i in range(1, N + 1)]
# First passenger
available_seats.remove(random.choice(available_seats))
# Other passengers
for i in range(2, n):
if i in available_seats:
available_seats.remove(i)
else:
available_seats.remove(random.choice(available_seats))
return available_seats
num_trials = 10000
num_successes = 0
for i in range(num_trials):
available_seats = simulate_seat_choosing(N, n)
if n in available_seats:
num_successes += 1
print('Fraction of successes = {:.4f}.'.format(num_successes / num_trials))
toc = time.time()
print('\nDone in {:.4f} seconds.'.format(toc-tic))
Here is my terminal output:
Fraction of successes = 0.9975.
Done in 6.3014 seconds.