Pattern race
Two players share a fair coin and flip it repeatedly, recording the sequence of heads () and tails () that appears. The first player wins if occurs before ; otherwise, the second player wins. What is the probability that the first player wins?
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 ; Player 2 wins on .
The transient states are , where denotes no useful suffix (start, or after a progress-resetting tail).
| State | Flip | Flip |
|---|---|---|
| P2 wins | ||
| P1 wins |
Remark on : after any run of heads, the longest suffix that prefixes a target is still (the length-2 prefix of ).
System of Equations
Let denote the probability that Player 1 wins from state .
Equation (3) reflects that is a trap: every additional keeps the game in , and the inevitable first completes , so Player 1 cannot win from .
Solution
Substituting into :
Combined with , we have . Substituting into :
The game begins in state , so Player 1 wins with probability .