Activity: simulation
Instructions:
- Work with a neighbor to answer the following questions
- To get started, download the class activity template file
- When you are finished, render the file as an HTML and submit the HTML to Canvas (let me know if you encounter any problems)
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.
- 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 oftakenare 0. - When a seat gets taken, change the corresponding entry in
takento 1 - Use
sampleto 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
forloop inside another. If so, make sure to use different indices in your loops