**Question:** A prisoner is trapped in a cell containing three doors. The first door leads to a tunnel that returns him to his cell after two days of travel. The second leads to a tunnel that returns him to his cell after three days of travel. The third door leads immediately to freedom.

- Assuming that the prisoner will always select doors 1, 2, and 3 with probabilities 0.5, 0.3, 0.2, what is the expected number of days until he reaches freedom?
- Assuming that the prisoner is always equally likely to choose among those doors that he has not used, what is the expected number of days until he reaches freedom? (In this version, for instance, if the prisoner initially tries door 1, then when he returns to the cell, he will now select only from doors 2 and 3.)
- For parts (a) and (b) find the variance of the number of days until the prisoner reaches freedom.

**Analytical Solution****:**

We will solve this problem in the following way

- Part 1 and the variance from part 3
- Part 2 and the variance from part 3

Part 1 and the variance: Let E[T] be the expected time for the prisoner to escape. We can calculate this from applying conditionality as follows

E[T] = E[E[ T|Door ]]

E[T] = E[ T|Door_{1 }] P{ Door_{1} } + E[ T|Door_{2 }] P{Door_{2}} + E[ T|Door_{3 }] P{Door_{3}}

E[T] = 0.5(E[T] + 2) + 0.3(E[T] + 3) + 0.2(0) = 9.5

Simlarly,

E[T^{2}] = E[E[ T^{2}|Door ]]

E[T^{2}] = E[ T^{2}|Door_{1 }] P{ Door_{1} } + E[ T^{2}|Door_{2 }] P{Door_{2}} + E[ T^{2}|Door_{3 }] P{Door_{3}}

E[T^{2}] = 0.5(E[T]^{2}) + 2^{2}) + 0.3(E[T]^{2} + 3^{2}) + 0

use E[T^{2}] = 9.5 and we have : E[T^{2}] = 0.5((E[T]+2)^{2}) + 0.3((E[T]+3)^{2}) = 122.5

⇒ Variance = σ^{2} = E[T^{2}] – E[T]^{2} = 122.5 – 9.5^{2} = 32.25

⇒ σ = Sqrt(32.25) = 5.67891

Part 2 and the variance: Note about the notations here, E[T_{1}] would be the time to cross

would mean the expected time to

E[T] = E[ E[T_{1}]|Door_{1 }] P{ Door_{1} } + E[ E[T2]|Door_{2 }] P{Door_{2}} + E[ E[T3]|Door_{3 }] P{Door_{3}}

E[T] = E[ E[T_{1}]|Door_{1 }] ^{1}⁄_{3} + E[ E[T2]|Door_{2 }] ^{1}⁄_{3} + E[ E[T3]|Door_{3 }] ^{1}⁄_{3}

E[T] = (E[T_{1}] + 2) ^{1}⁄_{3} + (E[T_{2}] + 3) ^{1}⁄_{3} + E[ E[T3]|Door_{3 }] ^{1}⁄_{3}

E[T] = ^{5}⁄_{3} + (2E[T_{1}] + E[T_{2}]) ^{1}⁄_{3}

E[T_{1}] and E[T_{2}] are calculated as follows.

- E[T
_{1}] =^{1}⁄_{2}(3 + 0) - E[T
_{2}] =^{1}⁄_{2}(2 + 0)

Sustituting these from above, we get E[T] = ^{5}⁄_{2} and E[T^{2}] = 9.4613 givingVariance to be E[T^{2}] – E[T]^{2} = 9.4163 – 2.5^{2} = 3.1667 and σ = 1.79951

**Simulation Solution**

Note: I belive my assumptions of the calculations are wrong and there is a mistmatch of the simulated values and the calculated values. I will see why it is wrong.

**Code**

I have used Mathematica for simulation and representation. The code is provided below. You could try running it yourself!

Module[{samples = Range[10, 100, 10]}, DistributionChart[ Table[ Mean /@ Table[ Module[{t = 0, door := RandomChoice[{0.5, 0.3, 0.2} -> {2, 3, 0}], doorTemp}, While[True, doorTemp = door; If[doorTemp != 0, t += doorTemp, Break[] ] ]; t ] , 1000, sample] , {sample, samples}], ChartElementFunction -> "PointDensity", ChartLabels -> samples, ImageSize -> 788, GridLines -> {None, {9.5}}, PlotLabel -> Style["Part-1 Mean:\[Mu]", 16, Red]] ] Module[{samples = Range[10, 100, 10]}, DistributionChart[ Table[ Variance /@ Table[ Module[{t = 0, door := RandomChoice[{0.5, 0.3, 0.2} -> {2, 3, 0}], doorTemp}, While[True, doorTemp = door; If[doorTemp != 0, t += doorTemp, Break[] ] ]; t ] , 1000, sample] , {sample, samples}], ChartElementFunction -> "PointDensity", ChartLabels -> samples, ImageSize -> 788, GridLines -> {None, {9.5}}, PlotLabel -> Style["Part-1 Variance:\!\(\*SuperscriptBox[\(\[Sigma]\), \ \(2\)]\)", 16, Red]] ] Module[{samples = Range[10, 100, 10]}, DistributionChart[ Table[ Mean /@ Table[ Module[{time = 0, door := RandomChoice[ ConstantArray[Divide[1, 3], 3] -> {2, 3, 0}], doorTemp}, doorTemp = door; time += doorTemp; If[doorTemp == 2, time += RandomChoice[{3, 0}]; Break, If[doorTemp == 3, time += RandomChoice[{2, 0}]; Break, time += 0 ] ]; time ] , 1000, sample], {sample, samples}], ChartElementFunction -> "PointDensity", ChartLabels -> samples, ImageSize -> 788, GridLines -> {None, {2.5}}, PlotLabel -> Style["Part-2 Mean:\[Mu]", 16, Red]] ] Module[{samples = Range[10, 100, 10]}, DistributionChart[ Table[ Variance /@ Table[ Module[{time = 0, door := RandomChoice[ ConstantArray[Divide[1, 3], 3] -> {2, 3, 0}], doorTemp}, doorTemp = door; time += doorTemp; If[doorTemp == 2, time += RandomChoice[{3, 0}]; Break, If[doorTemp == 3, time += RandomChoice[{2, 0}]; Break, time += 0 ] ]; time ] , 1000, sample], {sample, samples}], ChartElementFunction -> "PointDensity", ChartLabels -> samples, ImageSize -> 788, GridLines -> {None, {2.5}}, PlotLabel -> Style["Part-2 Variance:\!\(\*SuperscriptBox[\(\[Sigma]\), \ \(2\)]\)", 16, Red]] ]

End of the post 😉