Solution (source code)

= Solution

Let $h(x)$ be the probability that the <simple random walk on the integer line>[simple symmetric random walk] starting at $x\in\{0,\ldots,n\}$ hits zero before $n$. The first-step recurrence is
$$
h(x)=\frac12h(x-1)+\frac12h(x+1),
\qquad
h(0)=1,\quad h(n)=0.
$$
The recurrence says that $h$ is affine, and the boundary values determine it:
$$
\boxed{h(x)=\frac{n-x}{n}}.
$$