Skip to content

davidp6/prisoner_puzzle

Repository files navigation

Code that runs simulations for the prisoner puzzle that Roy shared with us.


Prompt:

The names of 100 prisoners are placed in 100 wooden boxes, one name to a box, and the boxes are lined up on a table in a room.

One by one, the prisoners are led into the room; each may look in at most 50 boxes, but must leave the room exactly as he found it and is permitted no further communication with the others.

The prisoners have a chance to plot their strategy in advance, and they are going to need it, because unless every single prisoner finds his own name all will subsequently be executed.

Find a strategy for them which has probability of success exceeding 30%.


Code:

SimulatePrisonerPuzzle.r : main code that runs everything else

SimulateSampling.r : function that executes multiple iterations of a given sampling strategy

Random.r : function that implements a completely random sampling strategy


Approach:

Write different scripts in the style of Random.r that test out other strategies that the prisoners might take. See if they work.


About

Code to Simulate the Prisoner Puzzle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages