Sheldon Ross 10: Exercise 3.40

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.

  1. 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?
  2. 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.)
  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] P{ Door1 } + E[ T|Door] P{Door2} + E[ T|Door] P{Door3}

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

Simlarly,

E[T2] = E[E[ T2|Door ]]

E[T2] =  E[ T2|Door] P{ Door1 } + E[ T2|Door] P{Door2} + E[ T2|Door] P{Door3}

E[T2] = 0.5(E[T]2) + 22) + 0.3(E[T]2 + 32)  + 0

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

⇒ Variance = σ2  = E[T2] – E[T]2 = 122.5 – 9.52 = 32.25

⇒ σ = Sqrt(32.25) = 5.67891

 Part 2 and the variance: Note about the notations here, E[T1] would be the time to cross

 would mean the expected time to

E[T] = E[ E[T1]|Door] P{ Door1 } + E[ E[T2]|Door] P{Door2} + E[ E[T3]|Door] P{Door3}

E[T] = E[ E[T1]|Door] 13 + E[ E[T2]|Door] 13 + E[ E[T3]|Door] 13

E[T] = (E[T1] + 2) 13 + (E[T2] + 3) 13 + E[ E[T3]|Door] 13

E[T] = 53 + (2E[T1] +  E[T2]) 13

E[T1] and E[T2] are calculated as follows.

  • E[T1] = 12(3 + 0)
  • E[T2] = 12(2 + 0)

Sustituting these from above, we get E[T] = 52 and E[T2] = 9.4613 givingVariance to be E[T2] – E[T]2 = 9.4163 –  2.52 = 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 😉