Skip to content

Code to compute the probability of success using the optimal solution.

License

Notifications You must be signed in to change notification settings

JohnStephens1/100-prisoners-problem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

100-prisoners-problem

If you happen to be unfamiliar with the 100 prisoners problem:

The bottom line is, the chance of winning taking a random approach would equate to
(1/2)^100 ≈ 8e-33 %
vs. the proposed solution resulting in a chance of roughly a third.

The enormous difference between the two probabilities seems unreasonably large, and the chance of success at a third superficially seems dubious at best, since the chance for only two people choosing randomly would already be lower at (1/2)^2. = 1/4.

Therefore I wanted to test it out and see if things add up and figured other people may be interested in seeing it for themselves.

The code:

There are two main files, one Jupyter Notebook, one normal Python file, but both are essentially identical. I personally find the notebook easier and more enjoyable to work and play around with.

The probability of success can be computed using the function

compute_pbb(repeats, n_total)

where repeats is the number of times the experiment is run and n_total the number of prisoners.

  • Any natural number can be chosen for repeats, while a higher number of runs will result in a more accurate probability for the given test.
  • n_total can be assigned to any positive even number, so the problem can be tested with for example a thousand prisoners or only fifty, while the allowed number of boxes each prisoner may choose remains at half of the number of prisoners.

About

Code to compute the probability of success using the optimal solution.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published