Solution (source code)

= Solution

Let $T_i^+=\inf\{n\ge1:X_n=i\}$ be the first positive return time. A <recurrent state> is one for which
$$
\boxed{\mathbb P_i(T_i^+<\infty)=1.}
$$
The subscript means that the <Markov chain> starts at $i$. The positive-time condition distinguishes a genuine return from the automatic visit at time zero.