๐Ÿงฎ Brain Teaser

The Drunkard's Last Dollar: Gambler's Ruin with a Twist

A gambler starts with \1andplaysasequenceoffaircoinflips.Oneachflip,hewinsand plays a sequence of fair coin flips. On each flip, he wins$1withprobabilitywith probability1/2andlosesand loses$1withprobabilitywith probability1/2.Hestopswhenheisโˆ—โˆ—ruinedโˆ—โˆ—(reaches. He stops when he is **ruined** (reaches $0)orwhenhereaches) or when he reaches $n$.

Now consider a different question: instead of asking for the probability of reaching \nbeforeruin,askfortheโˆ—โˆ—expectednumberofstepsuntilthegameendsโˆ—โˆ—(eitherruinorreachingbefore ruin, ask for the **expected number of steps until the game ends** (either ruin or reaching$n),startingfrom), starting from $k$.

Show that the expected duration is k(nโˆ’k)k(n-k).

In particular, starting from \1withtargetwith target$n,theexpecteddurationis, the expected duration is n-1$.

martingaleoptional stoppingrandom walkgambler's ruinexpected hitting time

Answer: Gambler's Duration via Martingale

Key Idea / Intuition

The key is to find a martingale whose optional stopping gives the answer directly. For a simple symmetric random walk StS_t, both StS_t and St2โˆ’tS_t^2 - t are martingales. The first gives the win probability (linear in starting position); the second, when stopped at the exit time TT, gives E[T]\mathbb{E}[T] in terms of the starting position. This is a beautiful example of how martingales convert a seemingly hard expectation problem into simple algebra.


Formal Proof / Solution

Setup. Let S0=kS_0 = k, and let T=minโก{t:St=0ย orย St=n}T = \min\{t : S_t = 0 \text{ or } S_t = n\}. We want Ek[T]\mathbb{E}_k[T].

Step 1: StS_t is a martingale.

Since each step has mean zero, E[St+1โˆฃSt]=St\mathbb{E}[S_{t+1} \mid S_t] = S_t, so StS_t is a martingale.

By Optional Stopping (the game ends in finite time a.s.): E[ST]=S0=k.\mathbb{E}[S_T] = S_0 = k.

Also STโˆˆ{0,n}S_T \in \{0, n\}, so if pp is the probability of reaching nn: pโ‹…n+(1โˆ’p)โ‹…0=kโ€…โ€ŠโŸนโ€…โ€Šp=kn.p \cdot n + (1-p) \cdot 0 = k \implies p = \frac{k}{n}.

(This recovers the classical gambler's ruin formula.)

Step 2: Mt=St2โˆ’tM_t = S_t^2 - t is a martingale.

Compute: E[St+12โˆฃSt]=12(St+1)2+12(Stโˆ’1)2=St2+1.\mathbb{E}[S_{t+1}^2 \mid S_t] = \frac{1}{2}(S_t+1)^2 + \frac{1}{2}(S_t-1)^2 = S_t^2 + 1.

Therefore: E[Mt+1โˆฃFt]=St2+1โˆ’(t+1)=St2โˆ’t=Mt.โœ“\mathbb{E}[M_{t+1} \mid \mathcal{F}_t] = S_t^2 + 1 - (t+1) = S_t^2 - t = M_t. \checkmark

Step 3: Apply Optional Stopping to MtM_t.

By Optional Stopping (justified since TT has finite expectation and bounded increments): E[MT]=M0=k2โˆ’0=k2.\mathbb{E}[M_T] = M_0 = k^2 - 0 = k^2.

But also: E[MT]=E[ST2]โˆ’E[T].\mathbb{E}[M_T] = \mathbb{E}[S_T^2] - \mathbb{E}[T].

We already know STโˆˆ{0,n}S_T \in \{0, n\} with probabilities 1โˆ’k/n1 - k/n and k/nk/n, so: E[ST2]=knโ‹…n2+(1โˆ’kn)โ‹…0=kn.\mathbb{E}[S_T^2] = \frac{k}{n} \cdot n^2 + \left(1 - \frac{k}{n}\right) \cdot 0 = kn.

Therefore: k2=knโˆ’E[T]k^2 = kn - \mathbb{E}[T] Ek[T]=knโˆ’k2=k(nโˆ’k).\boxed{\mathbb{E}_k[T] = kn - k^2 = k(n-k).}

Step 4: The special case.

Starting from k=1k = 1 with target nn: E1[T]=1โ‹…(nโˆ’1)=nโˆ’1.\mathbb{E}_1[T] = 1 \cdot (n - 1) = n - 1.

Why this is beautiful. The answer k(nโˆ’k)k(n-k) is symmetric in kk and nโˆ’kn-k: the game lasts longest when you start in the middle (k=n/2k = n/2), which makes perfect intuitive sense. The martingale St2โˆ’tS_t^2 - t does all the work, turning a recursive system of equations into a one-line calculation.

Written to question file and answer below.

Source: Mathematical folklore / Mosteller-adjacent classic

Type: ProbabilitySource: Mathematical folklore / Mosteller-adjacent classicEdit on GitHub โ†—