Some chains have states you can never leave — absorbing states. Split P into a transient block Q and an absorbing block R. The fundamental matrix N = (I − Q)⁻¹ answers everything: Nᵢ⫺ is the expected visits to transient j starting from i, its row sums give the expected steps to absorption, and NR gives the probability of ending in each absorbing state. Gambler's ruin lives here.
Play gambler's ruin on {0..4} with absorbing ends and an adjustable bias — solve (not simulate) the expected steps to absorption and the probability of winning versus going broke: live demo
“You have to simulate the walk to know how long it lasts on average.” — no; the answer is a linear solve. Expected steps to absorption satisfy (I − Q)t = 1, and the win-probabilities satisfy (I − Q)a = R — one Gaussian elimination, no dice thrown. cited
Absorption is where randomness ends in certainty: eventually you are trapped, and the only questions are when and which — both answered without ever rolling a die. Kemeny–Snell 1960
On the canonical compiler, biased gambler's ruin on {0..4} (up-probability 0.6) gives, from the middle, both the expected steps and the exact win-probability 9/13 by relaxation — matching de Moivre's formula: