Gambler’s Ruin
Start with i dollars. Each play wins $1 with probability p and loses $1 with probability q = 1 − p. What is the probability of reaching N before hitting 0?
Probability of reaching N first
40.00%
q = 0.50
$0RUIN
$4START
$10GOAL
Run a simulation and compare it with the exact answer.
How to derive the formula
① Rearrange the recurrence
pPᵢ₊₁ − Pᵢ + qPᵢ₋₁ = 0
② Solve the difference equation
The characteristic roots are 1 and q/p.
③ Use the two boundaries
Enforce P₀=0 and Pₙ=1 to determine the constants.
Final answer
If p = q = 1/2:
If p = q = 1/2:
Pᵢ = i / N
Otherwise:
Pᵢ = [1 − (q/p)ⁱ] / [1 − (q/p)ᴺ]