So I've been working on this problem for hours and now I'm stuck.. I can't figure it out. I know my probability is messed up, in fact I think it should be around 50%?
You are at the airport waiting in line to board a plane. There are 99 other passengers and unfortunately for you, you are last in line. At the front of the line you recognize a colleague, Frank. Frank is known to randomly sit where he pleases instead of his assigned seat. All the other passengers, including yourself, behave in a more sane fashion:
- They will look to sit in their assigned seat, if that seat is available, theywill sit in their assigned seat.
- On the other hand, if their assigned seat is taken, they will pick a free seatat random to sit in.
- Create a function that runs a 10,000 iteration Monte Carlo simulation that estimates the probability that your seat will be taken
function boarding
trials = 10000;
P=100;
inmyseat=0;
x=0;
for i=1:trials
x=randi([1,100],1);
if x==1
break
else
for P=(99:-1:2)
y=randi([1,P],1);
if y==1
inmyseat = inmyseat+1;
break
end
end
end
end
prob=(inmyseat/trials)*100
end