Monte Carlo Simulation of Markov Prisoner

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram CDF Player or other Wolfram Language products.

Requires a Wolfram Notebook System

Edit on desktop, mobile and cloud with any Wolfram Language product.

This Demonstration is based on a homework problem that has been in numerous editions of [1] and [2]: 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.


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.


Contributed by: Paul Savory (University of Nebraska-Lincoln) (March 2011)
Open content licensed under CC BY-NC-SA



Which book?

[1] S. Ross, Introduction to Probability Models, ed., Burlington, MA: Academic Press, 2007.

[2] S. Ross, A First Course in Probability, Englewood Cliffs, NJ: Prentice Hall, 2010.

Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.