Monte Carlo Simulation of Markov Prisoner
Requires a Wolfram Notebook System
Interact on desktop, mobile and cloud with the free Wolfram Player or other Wolfram Language products.
This Demonstration is based on a homework problem that has been in numerous editions of  and : A prisoner is in a dungeon with three doors. One door leads to freedom, one door leads to a long tunnel, and a third door leads to a short tunnel. The two tunnels return the prisoner to the dungeon. If the prisoner returns to the dungeon, he attempts to gain his freedom again, but his past experiences do not help him in selecting the door that leads to freedom, that is, we assume a Markov prisoner. The prisoner’s probability of selecting the doors are: 20% to freedom, 50% to the short tunnel, and 30% to the long tunnel. Assuming the travel times through the long and short tunnels are 3 and 2 hours, respectively, our goal is to determine the expected number of hours until the thief selects the door which leads to freedom.[more]
Mathematically, you can solve this problem using expected values. This Demonstration showcases solving it using Monte Carlo simulation. The simulation lets you see the number of hours until freedom is reached for the specified number of simulation trials. The red dot on the histogram indicates the average number of hours. As the number of trials increases, the mean of the simulation results converges to the theoretical value (9.5 for the probabilities defined in the problem). You can also explore the option of the doors having equal probability and changing the number of hours for each tunnel.[less]
Contributed by: Paul Savory (University of Nebraska-Lincoln) (March 2011)
Open content licensed under CC BY-NC-SA
 S. Ross, Introduction to Probability Models, ed., Burlington, MA: Academic Press, 2007.
 S. Ross, A First Course in Probability, Englewood Cliffs, NJ: Prentice Hall, 2010.
"Monte Carlo Simulation of Markov Prisoner"
Wolfram Demonstrations Project
Published: March 7 2011