Pattern race

FreeProbabilityHardJane StreetSIGFive Rings

Two players share a fair coin and flip it repeatedly, recording the sequence of heads (HH) and tails (TT) that appears. The first player wins if HTHHTH occurs before HHTHHT; otherwise, the second player wins. What is the probability that the first player wins?

Solution

Idea

Track the game state as the longest suffix of the flip sequence that is a prefix of either target pattern. This yields a small Markov chain whose first-step equations determine the win probability exactly.

States and Transitions

Target patterns: Player 1 wins on HTHHTH; Player 2 wins on HHTHHT.

The transient states are {ε,H,HH,HT}\{\varepsilon,\, H,\, HH,\, HT\}, where ε\varepsilon denotes no useful suffix (start, or after a progress-resetting tail).

StateFlip HHFlip TT
ε\varepsilonHHε\varepsilon
HHHHHHHTHT
HHHHHHHHP2 wins
HTHTP1 winsε\varepsilon

Remark on HHHHHHH \xrightarrow{H} HH: after any run of heads, the longest suffix that prefixes a target is still HHHH (the length-2 prefix of HHTHHT).

System of Equations

Let psp_s denote the probability that Player 1 wins from state ss.

pε=12pH+12pε    pε=pH(1)p_{\varepsilon} = \tfrac{1}{2}p_H + \tfrac{1}{2}p_{\varepsilon} \implies p_{\varepsilon} = p_H \tag{1} pH=12pHH+12pHT(2)p_H = \tfrac{1}{2}p_{HH} + \tfrac{1}{2}p_{HT} \tag{2} pHH=12pHH+120    pHH=0(3)p_{HH} = \tfrac{1}{2}p_{HH} + \tfrac{1}{2}\cdot 0 \implies p_{HH} = 0 \tag{3} pHT=121+12pε(4)p_{HT} = \tfrac{1}{2}\cdot 1 + \tfrac{1}{2}\,p_{\varepsilon} \tag{4}

Equation (3) reflects that HHHH is a trap: every additional HH keeps the game in HHHH, and the inevitable first TT completes HHTHHT, so Player 1 cannot win from HHHH.

Solution

Substituting (3)(3) into (2)(2):

pH=12pHT.p_H = \tfrac{1}{2}p_{HT}.

Combined with (1)(1), we have pε=pH=12pHTp_{\varepsilon} = p_H = \tfrac{1}{2}p_{HT}. Substituting into (4)(4):

pHT=12+1212pHT=12+14pHT.p_{HT} = \frac{1}{2} + \frac{1}{2}\cdot\frac{1}{2}p_{HT} = \frac{1}{2} + \frac{1}{4}p_{HT}. 34pHT=12    pHT=23.\frac{3}{4}p_{HT} = \frac{1}{2} \implies p_{HT} = \frac{2}{3}. pε=1223=13.p_{\varepsilon} = \frac{1}{2}\cdot\frac{2}{3} = \boxed{\dfrac{1}{3}}.

The game begins in state ε\varepsilon, so Player 1 wins with probability 13\dfrac{1}{3}.

Related problems