Premium problem60. Random Walk to a Boundary

Hard Locked

A walker starts at 0 and each step moves by an amount drawn uniformly from [-3, -2, -1, 1, 2, 3]. Return the expected number of steps until ∣position∣≥L|\text{position}| \geq L.

Let ExE_x be the expected remaining steps from position x. For every interior position:

Ex=1+16∑sEx+s,Ey=0 when ∣y∣≥LE_x = 1 + \frac{1}{6}\sum_{s} E_{x+s}, \qquad E_y = 0 \text{ when } |y| \geq L

That is a linear system in the interior states, so build it and solve it rather than iterating to convergence.

Input

5

Output

6.725490196078429

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)