How to use the coin flip pattern waiting time calculator
- Enter Pattern A as heads (H) and tails (T), for example THH. Patterns can be up to 10 flips long.
- Enter Pattern B in the same way. The two patterns must differ, and neither can contain the other.
- Enter the chance of heads for one flip. Use 0.5 for a fair coin.
- Read the chance that each pattern shows up first, and the average number of flips to see each one.
Formula
Average wait for a pattern = sum of 1 / P(prefix) over every prefix of the pattern that is also a suffix of it
For a fair coin, P(prefix) = 2^(-length), so each prefix that matches a suffix adds 2^length
The chance that A comes before B is found by following the flips as a chain whose states are the longest piece of a pattern matched so far
The chain is solved exactly for the chance of ending on pattern A
The prefixes that are also suffixes include the whole pattern itself, and they are why HH (6 flips) takes longer than HT (4 flips).
THH against HHT, and HH against HT
With a fair coin, THH and HHT both take 8 flips on average, yet THH comes first with probability 75 percent, which is 3 to 1 odds. This is Conway's well-known surprise: the pattern with the same wait wins three times in four.
HH takes 6 flips on average while HT takes 4, but the two are equally likely to come first, 50 percent each. HTH and THT both take 10 flips and are also equal. With a coin that lands heads 60 percent of the time, HH comes before TH only 36 percent of the time, and the waits are 4.4444 and 4.1667 flips.
Why overlaps matter
A pattern that overlaps with itself, like HH, tends to take longer, because after a near miss you have less to build on. HH needs a second H after a first, but if the next flip is a T you start over from nothing. HT can never overlap itself, so each failure only costs one flip. The average wait counts exactly those self-overlaps.
A race between two patterns is not decided by the waits alone, which is why the results can seem backward. For runs of the same result, use the streak probability calculator. For the number of trials to reach a number of successes, see the geometric and negative binomial calculator.
Checking the answer
The race result is solved exactly with a small linear system and does not use simulation. You can confirm it by hand for short patterns. The numbers in the examples were also checked by tracking the full probability of every sequence of flips until almost all of it had ended on a pattern.
For the chance of a number of heads in a set number of flips, use the binomial probability calculator.
Assumptions and limits
- Flips are independent, and the chance of heads is the same on every flip.
- Patterns use only H and T, and are at most 10 flips long.
- Neither pattern contains the other, otherwise the shorter one always shows up first or together.
- Probabilities are exact for the model, not estimates from simulation.
Frequently asked questions
How many flips do I expect to see HTH?
For a fair coin it is 10 flips. The wait is 2 + 8 = 10, from the prefixes H and HTH that are also suffixes.
Why does HT come sooner than HH?
HH overlaps itself, so a failure costs more. HT takes 4 flips on average while HH takes 6.
Which pattern comes first more often?
It is not the one with the shorter wait. THH beats HHT three times in four even though both average 8 flips.
Does it work for a biased coin?
Yes. Enter the chance of heads and the page uses it for the waits and for the race.