Minimising the distance covered I am trying to solve the question: You are trying to get to go from A to B 10 times. At each journey, a coin is flipped and if its heads, a wall appears in the middle as in scenario 2. If tails, no wall appears. Construct a method to minimize the distance covered. What is the expected distance covered over those 10 walks?

Attempt: we can treat the 10 trials independently, and the expected distance of any one walk is 0.5 ( 2m) + 0.5 (4m) = 3m, so the expected total distance covered is 30 metres. But what strategy can we construct to minimize this distance? My only thought is to walk along the diagonals so that we are guareenteed to walk $2\sqrt{2}$ each walk, this minimizes the distance to approximately 28 metres.
 A: I assume that the coin is tossed each trip only upon reaching the wall position, and also that the diagram is a top view so we are walking around, not climbing over, the wall.
Firstly, the default expected distance should probably assume, in the case of tails, that you walk diagonally on the second part of the trip, so we would have $E(D) = \frac{1}{2}2 + \frac{1}{2}(2+\sqrt{2}) = 2+1/\sqrt{2}$.
The idea to walk the diagonal on the first half assumes the worst case (tails). There might be a middle ground that's optimal. Say you aim for a spot on the wall at distance $0\leq x\leq 1$ from its centre. Then the expected distance of one trip is
\begin{eqnarray*}
E(D) &=& \frac{1}{2} (2\sqrt{x^2+1}) + \frac{1}{2}(\sqrt{x^2+1} + (1-x) + \sqrt{2}) \\
&& \\
&=& \frac{3}{2} \sqrt{x^2+1} - \frac{x}{2} + \frac{1}{2} + \frac{1}{\sqrt{2}} \\
&& \\
\dfrac{dE(D)}{dx} &=& \frac{3x}{2\sqrt{x^2+1}} - \frac{1}{2} = 0 \implies 3x = \sqrt{x^2+1}\implies x = \dfrac{1}{2\sqrt{2}}. \\
\end{eqnarray*}
With this value of $x$ we get $E(D)=\dfrac{6+\sqrt{2}}{2\sqrt{2}}.\;$ And $10E(D) = \dfrac{30+5\sqrt{2}}{\sqrt{2}}\approx 26.21$.
