Activity: simulation

Instructions:

Probability simulation: theater seating

Suppose there are exactly 100 seats in a movie theater. Further, suppose the movie theater has imposed a new ticketing system where each person’s ticket has an assigned seat number. Consider the case where the movie is sold-out (all 100 seats will be taken) and the first person in the theater lost their ticket and takes a random seat. Each subsequent person attempts to go to their seat. If their seat is open, they take it. Otherwise, to avoid confrontation, they choose a random seat.

  1. Conduct a simulation to assess the probability that the last person into the theater will get their assigned seat.

Tips: Here are some tips for one approach to this simulation.

  • Create a vector seats, containing the numbers 1,…,100 in order, to represent the (numbered) seats in the theater
  • Create a vector, taken, to represent which seats have been taken. At the beginning of each run of the simulation, all entries of taken are 0.
  • When a seat gets taken, change the corresponding entry in taken to 1
  • Use sample to randomly choose a seat from the ones available
  • seats[taken == 0] will tell you which seats are available
  • It is crucial to treat the first person separately from the rest. The first person always chooses a random seat. The other 99 people only choose a random seat if their seat is already taken.
  • Begin by coding one run of the simulation. That is, all 100 people take a seat. Check whether the last person in the theater got their assigned seat. Then repeat the simulation many times
  • Your code may involve nesting one for loop inside another. If so, make sure to use different indices in your loops