Created
October 26, 2017 01:29
-
-
Save jaimemarijke/41839eca7370564ff8dd5fc6e633c919 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Problem\n", | |
"One hundred prisoners are put into 100 completely isolated cells, numbered 1 to 100. Once they are in their cells, they cannot communicate with each other in any way. They are taken by the warden one at a time, but in no particular order, to a special room, Cell 0, in which there are two levers. As the prisoners enter the room, each lever is either up or down, but the levers’ starting positions are unknown. When in the room, a prisoner must flip exactly one of the levers. At any point, any prisoner may declare to the warden that all of the prisoners have been to the room. (The warden will take prisoners to the room indefinitely until someone makes a guess.) If the prisoner is correct, they are all released. If not, they are all executed.\n", | |
"\n", | |
"Knowing these rules, what strategy can the prisoners devise beforehand that will guarantee their release? How many trips to Cell 0 will it take on average before they are released?\n", | |
"\n", | |
"\n", | |
"# Solution\n", | |
"\n", | |
"## Overview\n", | |
"\n", | |
"Designate one prisoner (Prisoner #100) as the one who will count how many times all other prisoners have visited Cell 0.\n", | |
"\n", | |
"Designate one lever (`left_lever`) as the one that will indicate a prisoner has visited the cell. The other lever (`right_lever`) is basically useless, and is only toggled because the prisoners are required to toggle something every time they enter the cell. (Incidentally, it seems that this problem would be conceptually simpler if there was only one toggle, and prisoners were *not* required to toggle anything when they visit Cell 0.)\n", | |
"\n", | |
"Prisoners 1-99 will each \"record\" the fact that they visited the cell by toggling `left_lever` from the down to up position. If `left_lever` is already toggled up when they enter the cell, then their visit isn't \"recorded\" and they must wait to try again (and in the meantime just toggle `right_lever`). Once they have successfully toggled `left_lever` once, they no longer attempt to do so and always toggle `right_lever`.\n", | |
"\n", | |
"Prisoner 100 will be the one who tallies the count of other prisoners' visits (in his or her head) by counting every time s/he enters the cell and sees `left_lever` is toggled up. If it is up, s/he will reset it to down. Otherwise, s/he too will just toggle `right_lever`.\n", | |
"\n", | |
"Therefore, Prisoner 100 waits until s/he had counted 99 \"visits\" and then asks to be released.\n", | |
"\n", | |
"Except...\n", | |
"\n", | |
"## What about those unknown initial conditions?\n", | |
"Unfortunately, the fact that the initial conditions are unknown is a bit of a curve ball - what if `left_lever` starts out toggled up and Prisoner 100 mistakenly counts that as a visit from a fellow prisoner? \n", | |
"\n", | |
"To address this, we can modify our solution so that each prisoner is required to have two \"recorded\" visits, i.e. they must toggle `left_lever` from the down to up position exactly twice. Then, instead of counting up only 99 visits, Prisoner 100 looks for 198 visits. \n", | |
"\n", | |
"Why does this work? If every prisoner has to have two \"recorded\" visits to Cell 0, then `left_lever` might be toggled to the up position 198 or 199 times, depending on its initial state:\n", | |
"\n", | |
"```\n", | |
"99 prisoners * 2 visits + 1 if the lever started in the up position = 199 toggles\n", | |
"```\n", | |
"\n", | |
"Prisoner 100 can (and should!) safely call it at 198 toggles, because even if only 98 prisoners have visited the cell twice and the toggle started out up, the 99th prisoner must have visited at least once:\n", | |
"\n", | |
"```\n", | |
"98 prisoners * 2 visits + 1 toggle from initial conidtions + 1 visit from 99th prisoner = 198 toggles\n", | |
"```\n", | |
"\n", | |
"If the toggle started down, then there will only be 198 toggles total, and Prisoner 100 would wait forever without seeing the 199th up toggle.\n", | |
"\n", | |
"\n", | |
"## Algorithm\n", | |
"\n", | |
" - For prisoners 1-99, if they visit the cell and the `left_lever` is down, toggle it to up. Otherwise toggle `right_lever`. Only toggle `left_lever` up twice, afterwards always just toggle `right_lever`.\n", | |
" - For prisoner 100, if `left_lever` is up, count that as a 'visit' for another prisoner, and toggle it to down. Otherwise toggle `right_lever`. After s/he has counted 198 'visits', demand to be released!\n", | |
" \n", | |
"### Addendum / side note on lever orientation\n", | |
"There would have to be some prearranged agreement on how to distinguish the two levers and their two positions. I've assumed that the levers are left and right of each other and that they toggle up and down. The prisoners would want to make arragements for various orientations of the levers. \n", | |
"\n", | |
"# Probability\n", | |
"I could try to dredge up college statistics to figure out the answer, or I could do what I do best and write a program for that simulates it, run multiple trials, and finds the average number of iterations.\n", | |
"\n", | |
"Based on this program, it looks like the average number of iterations is somewhere around 20,500. (Try running it for yourself below!)\n", | |
"\n", | |
"If it takes only 1 minute per iteration, and the warden works around the clock, it will take on average ~14 days for the prisoners to be released\n", | |
"\n", | |
"```\n", | |
"(20500 iterations) * (1 minute/iteration) / (60 minutes/hour * 24 hours/day) = 14 days\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 151, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from collections import defaultdict\n", | |
"import random\n", | |
"\n", | |
"class PrisonersChallenge():\n", | |
" def __init__(self):\n", | |
" self.prisoners = range(1,101)\n", | |
"\n", | |
" # Levers can start in either up (True) or down (False) positions.\n", | |
" lever_options = (True, False)\n", | |
" self.left_lever = random.choice(lever_options)\n", | |
" self.right_lever = random.choice(lever_options)\n", | |
"\n", | |
" # Stores the number of times each prisoner (1-99) has a \"recorded\" visit to the cell\n", | |
" # and prisoner 100's count of others' visits\n", | |
" self.visit_count = defaultdict(lambda: 0)\n", | |
"\n", | |
" # How many iterations did it take for prisoners to be released?\n", | |
" self.iterations = 0\n", | |
"\n", | |
" def run_iteration(self):\n", | |
" self.iterations += 1\n", | |
"\n", | |
" prisoner = random.choice(self.prisoners)\n", | |
" release_prisoners = False\n", | |
"\n", | |
" if prisoner == 100:\n", | |
" # If left_lever is toggled up, count it as a visit and reset it\n", | |
" if self.left_lever:\n", | |
" self.visit_count[prisoner] += 1\n", | |
" self.left_lever = not self.left_lever\n", | |
"\n", | |
" else:\n", | |
" self.right_lever = not self.right_lever\n", | |
"\n", | |
" # If 198 visits have been counted, ask to be released!\n", | |
" if self.visit_count[prisoner] >= 198:\n", | |
" release_prisoners = True\n", | |
"\n", | |
" else:\n", | |
" # If left_lever isn't already toggled up, and this prisoner hasn't already had 2 visits recorded, toggle it up\n", | |
" if (not self.left_lever) and self.visit_count[prisoner] < 2:\n", | |
" self.left_lever = not self.left_lever\n", | |
" self.visit_count[prisoner] += 1\n", | |
" else:\n", | |
" self.right_lever = not self.right_lever\n", | |
"\n", | |
" return release_prisoners" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 152, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def run_trial():\n", | |
" '''\n", | |
" Run a single trial of the Prisoner's Challenge\n", | |
" \n", | |
" @return: how many iterations it took\n", | |
" '''\n", | |
" release_prisoners = False\n", | |
" challenge = PrisonersChallenge()\n", | |
"\n", | |
" while(not release_prisoners):\n", | |
" release_prisoners = challenge.run_iteration()\n", | |
" \n", | |
" return challenge.iterations\n", | |
"\n", | |
"def run_trials(number_of_trials):\n", | |
" '''\n", | |
" Run multiple trial of the Prisoner's Challenge, and record how many iterations it took\n", | |
" \n", | |
" @return: a list of the iteration count for each trial\n", | |
" '''\n", | |
" trials = []\n", | |
" for i in range(number_of_trials):\n", | |
" iteration_count = run_trial()\n", | |
" trials.append(iteration_count)\n", | |
" \n", | |
" return trials" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 164, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Average # iterations: 20476\n" | |
] | |
} | |
], | |
"source": [ | |
"NUMBER_OF_TRIALS = 100000\n", | |
"\n", | |
"trials = run_trials(NUMBER_OF_TRIALS)\n", | |
"\n", | |
"print \"Average # iterations:\", sum(trials)/len(trials)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 165, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZUAAAEKCAYAAADaa8itAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHlVJREFUeJzt3X+UHWWd5/H3hyDIIWKCYG9McDpocAbImCEtMDPqdkQx\ngDtBVzE5HEkEiQg4o5NxDOoRDyxzosjqogxulAxwZI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T5Km7ktVrSD0o5/HlE7ExHK++OiGfT0dyqVPTmpzyn\npPV1ljZ5SbHZmCzpT1Oux6V5UyhGxd0NPCbpK8CrKYbtPzGtawx2QPKRiu0Xohih9Wbgb/disTVR\n3JdiN8VQFP1FYT1FIem3JCL+GBEbKYrPn1LcSOs8SQ9SDIfxKmBSar96YEFJ3kRx06T/iGI49Fso\nbpTWqNOB+SmHHuDlwGvTvBUR0X+vHAH/JOkhimFrxvPi7QAG82aKoUqIiEcpbrbVX1RWRsQzEfH/\nKI7G/oTifTlW0lckTQeerbFOOwD4SMX2J1+mGKvpX0qxPtIfT5IOohjXqd/u0vQfS6//yJ7fjYFj\nGQXFf9QfjYjl5RmSuoHnGkt/rwn4rxHx2IAcThmQw7nA0RTjQP0hjR788n3Ybvl9e57iLpVPS3oj\nxU2fLgLOoRhTyg4wPlKx/Ub6y3wJRad3v80Up5sA/gZ4WQOrfp+kg1I/y7EUgwkuBz6Shh9H0nGS\nDh9mPauB/yzpKEmjgFnAj/Yij99Q3Dq233Lgo1Jxrw9JfzHIcq8EdqSCMo3iyKLW+sp+TFGMSKe9\nXkux3zWl02oHRcRtwGcoTr/ZAchFxfY311Dc+6Lf1yn+I/8J8Jc0dhTxfykKwl3ARem0zzcoTv3c\nnzq3/yfDHPlHcTfK+cA9FKPIrouIO/cij3uA4/s76oErKYrkQ5IeTq9ruQXokrSeoi/o0ZTPUxR9\nQRsGXiAA/DNwUFrmW8CcdJpwMOOBnnQq7pu8eMdBO8B4lGIzM8vGRypmZpaNi4qZmWXjomJmZtm4\nqJiZWTYuKmZmlo2LipmZZeOiYmZm2biomJlZNv8fNwQDAWvFlO4AAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x1047195d0>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"import matplotlib.pyplot as plt\n", | |
"plt.hist(trials, bins=20)\n", | |
"plt.xlabel('Number of iterations')\n", | |
"plt.ylabel('Count')\n", | |
"plt.grid()\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.13" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment