Double or nothing

You walk into a casino with $5. You bet $1 on each round of a fair coin flip. If it's heads, you gain $1. Tails, you lose $1. You keep playing until you either reach $10 or go broke.

What do you think?
With $5, trying to reach $10 on fair coin flips ($1 each), what's the probability you go broke?

Run the simulation. Watch the gambler's fortune trace a path between $0 and the goal:

Gambler's Ruin
Theory: P(ruin) = 50.0% | P(reach $10) = 50.0%

With a fair coin, the ruin probability is 50%. Starting halfway to the target gives a symmetric outcome. But what happens when the game is slightly unfair?

The house edge changes everything

Casinos don't offer fair bets. Roulette gives you roughly a 47.4% chance of winning an even-money bet (because of the green zero). That 2.6% edge seems tiny.

What do you think?
With $5, goal $10, and a 47% win probability per bet (instead of 50%), roughly what's P(ruin)?

Go back to the simulator, slide the win probability down to 47%, and watch what happens. The paths tend to drift downward.

The formula

The gambler's ruin has a closed-form solution.

Gambler's Ruin

A gambler starts with $ii and bets $11 per round. Each round is won with probability pp and lost with probability q=1pq = 1 - p. The game ends when the gambler reaches $NN or $00.

Fair game (p=q=1/2p = q = 1/2): P(ruin)=1iNP(\text{ruin}) = 1 - \Large\frac{i}{N}

Unfair game (pqp \neq q): P(ruin)=(q/p)i(q/p)N1(q/p)NP(\text{ruin}) = \Large\frac{(q/p)^i - (q/p)^N}{1 - (q/p)^N}

Deriving the Ruin Probability
ri=P(ruin starting from $i)r_i = P(\text{ruin starting from } \$i)
Let r_i be the probability of going broke when starting with $i.
Step 1 of 6

Explore how ruin probability changes with starting money and win probability:

Ruin Probability
0%25%50%75%100%$0$2$5$7$10starting moneyP(ruin)
P(ruin) at $1
90.0%
P(ruin) at $5
50.0%
Edge
Fair game

When p<0.5p < 0.5, the curve bows upward: even generous starting positions barely help. When p>0.5p > 0.5, the curve bows downward: even modest starting capital gives strong protection. The shape of this curve is an exponential, not a line.

Why "just quit while ahead" doesn't work

People often suggest: "Win a few, then leave." The gambler's ruin shows why this intuition fails.

What do you think?
You start with $100 at a casino where p = 0.49. You'll leave once you've won $1 (reach $101) or lost everything. What's P(ruin)?

The math is merciless: if p<1/2p < 1/2, the longer you play, the more certain your ruin becomes. As the target NN grows, the ruin probability approaches 1, regardless of starting capital.

For p<1/2p < 1/2 and NN \to \infty: P(ruin)1P(\text{ruin}) \to 1

This is why casinos are profitable businesses. They have an infinite bankroll and a slight edge. Time is on their side.

Competition appearances

The gambler's ruin shows up across math competitions and programming contests:

Math competitions:

  • Putnam problems on absorbing Markov chains often reduce to gambler's ruin
  • AIME/USAMO problems involving sequential games with stopping conditions
  • Physics olympiads use the same recurrence for particle diffusion

Programming challenges:

  • Project Euler problems on random processes with absorbing barriers
  • Codeforces rating problems: "probability a player reaches rating X before dropping to Y"
  • Interview questions at quant trading firms: this is a favorite at Jane Street and Two Sigma

Related probability results:

  • With a fair coin and no upper barrier (N=N = \infty), the walk returns to 0 with probability 1 but the expected time to return is infinite
  • In 2D, a random walk also returns to the origin with probability 1
  • In 3D and higher, the walk escapes to infinity with positive probability (Polya's recurrence theorem)
Fair game, start with $3, goal is $7. P(ruin)? (decimal like 0.57)
1/4

The takeaway

The gambler's ruin comes down to this: a small per-round disadvantage, compounded over many rounds, becomes near-certain defeat. The recurrence ri=pri+1+qri1r_i = p \cdot r_{i+1} + q \cdot r_{i-1} is a building block for Markov chain analysis, and the exponential solution (q/p)i(q/p)^i shows up wherever you have biased random walks with absorbing barriers. In competitions, when you see a process that can end in "win" or "lose" states with probabilistic transitions, think gambler's ruin.