Escaping Prisoner Probability Question Question: A prisoner is trapped in a cell containing three doors. The first door leads to a tunnel which
returns him to his cell after two days travel. The second door leads to a tunnel that returns
him to his cell after three days travel. The third door leads immediately to freedom. 
(a) Assuming the prisoner will always select doors 1, 2 and 3 with probabilities 0.5, 0.3 and
0.2 respectively, what is the expected number of days until he reaches freedom?
(b) Calculate the variance of the number of days until the prisoner reaches freedom.
My Attempt so far: I've used first step decomposition to get an answer of $9.5$ days to the first part of the question, but I have no idea how to find the variance for part (b). I've tried using the Law of Total Variance but got nowhere. I don't know whether you're supposed to use $Var(X) = E(X^2) - (E(X))^2$, where $X$ is the number of days taken to reach freedom. If so, how do you go about finding $E(X^2)$? Any help would be greatly appreciated. 
 A: To calculate $E[X]$ you presumably did $$E[X] = 0.5 E[X+2]+ 0.3 E[X+3]+0.2 E[0]$$ i.e. $$E[X] = 0.5 E[X] + 0.5 \times 2+ 0.3 E[X] +0.3 \times 3$$ and then solved to find $E[X]$.
Similarly you can do $$E[X^2] = 0.5 E[(X+2)^2]+ 0.3 E[(X+3)^2]+0.2 E[0^2]$$ i.e. $$E[X^2] = 0.5 E[X^2] +0.5 \times 4 E[X] +0.5 \times 4 + 0.3 E[X^2] +0.3 \times 6 E[X]+0.3 \times 9$$ and you already know $E[X]$.  Then use  $Var(X) = E[X^2] - (E[X])^2$
A: A general approach: Let $X$ the time when de prisoner is free. We will calculate $m_X(t)=E[e^{tX}]$. Let $Y$ the first door choosen.
Note that
$\begin{eqnarray}E[e^{tX}]&=&\sum_{y}E[e^{tX}|Y=y]P(Y=y)\\
&=&E[e^{tX}|Y=1]0.5+E[e^{tX}|Y=2]0.3+E[e^{tX}|Y=3]0.2\end{eqnarray}$
Now, given $Y=1$, $X=2+Z$ where $Z$ is the number of additional days to freedom after the prisoner returned to his cell. But once he returned, the experiment is newly the same. Then $X$ and $Z$ have the same distribution. Thus $E[e^{tX}|Y=1]=E[e^{t(2+Z)}]=e^{2t}E[e^{tZ}]=e^{2t}E[e^{tX}]$. 
Analogously $E[e^{tX}|Y=2]=e^{3t}E[e^{tX}]$.
Finally, $E[e^{tX}|Y=3]=1$, cause $X=0$.
Therefore $m_X(t)=E[e^{tX}]=0.5e^{2t}m_X(t)+0.3e^{3t}m_X(t)+0.2$. Thus $m_X(t)=\dfrac{0.2}{1-0.5e^{2t}-0.3e^{3t}}$.
Now it is easy to finish:
$E[X]=m_X^\prime(0)=\left.\dfrac{-0.2(-e^{2t}-0.9e^{3t})}{(1-0.5e^{2t}-0.3e^{3t})^2}\right|_{t=0}=9.5$ 
$E[X^2]=m_X^{\prime\prime}(0)=\left.0.2\left(\dfrac{2(-e^{2t}-0.9e^{3t})^2}{(-0.5e^{2t}-0.3e^{3t}+1)^3}-\dfrac{-2e^{2t}-2.7e^{2t}}{(-0.5e^{2t}-0.3e^{3t}+1)^2}\right)\right|_{t=0}=204$, so $Var(X)=204-9.5^2=113.75$
