If n = 2, the probability is 1/4. If n = 3, the probability is 3/8 (HHH, HHT, THH). If n = 4, the probability turns out to be 8/16. The denominator of the probability fraction, in its unsimplified form, will be 2^n. The challenge is to find the numerator. For simplify in wording, here are the phrase abbreviations:
- "at least a pair of consecutive heads" --> "HH"
- "no pair of consecutive heads" --> "!HH"
- "heads" --> "H" and "tails" --> "T"
n = 2 | n = 3 | n = 4 |
HT | HTT | HTTT |
TH | THT | THTT |
TT | TTT | TTTT |
TTH | TTHT | |
HTH | HTHT | |
TTTH | ||
THTH | ||
HTTH |
While the ordering wasn't particularly important at this stage, notice that the first three rows of n=3 was conveniently laid out so that they are simply addition of one more T from the same row under n=2; same for going from n=3 to n=4. Now take a looks specifically at n=3. The first toss can be H or T. For 3 flips featuring !HH:
- If the 1st flip is T, there are 3 possible combinations (THT, TTT, TTH)
- If the 1st flip is H, there are 2 possible combinations (HTT, HTH)
- For 2 of those combinations ending with T, each will produce 3 further possible combinations in 3rd and 4th flip to keep the !HH property
- For the remaining combination ending with H, it will produce 2 further possible combinations instead
The answer actually indirectly lies in q'(3). Observe the column of combinations above for n=2 and n=3. In particular, look at the last two rows. Similarly, compare n=3 and n=4 rows and observe the last three rows of n=4. What are those "extra" rows without something to the left of it in the table? They all end in H, and the rest of the term (without the final H) are exactly the combinations that end in T for the previous column.
Let's formulate some ideas for q'(5). Take q'(3) = 5 to start.
- Each of those 5 combinations will produce at least two possible combinations (of 4th and 5th flip) to keep the !HH property ongoing at n=5
- Furthermore, some portion of those 5 combinations will produce a third combination, if it ends in T
- Summing them together, q'(5) = 2*q'(3) + (q'(4) - q'(3))
- That simplifies to q'(5) = q'(3) + q'(4)
- Multiple each term by either 2^n, 2^(n-1), or 2^(n-2)
- That ends up being 4*q(n) = 2*q(n-1) + q(n-2)
- Simplify to q(n) = (1/2)*q(n-1) + (1/4)*q(n-2) with conditions that q(1) = 1, q(2) = 3/4
- Finally, p(n) = 1 - (1/2)*(1-p(n-1)) - (1/4)*(1-p(n-2))
- Given F(n+2) = q'(n)
- q(n) = F(n+2) / (2^n)
- p(n) = 1 - F(n+2) / (2^n)
int until = 0;
System.out.print("n = ? ");
until = reader.nextInt();
for(int i=1; i<=until; i++)
{
System.out.println(i + ": " + (1-fib(i)));
}
public static double fib(int run)
{
if(run == 1)
return 1;
else if(run == 2)
return 0.75;
else
return (0.5)*fib(run-1) + (0.25)*fib(run-2);
}
The condensed results are as follows:
n | p(n) |
1 | 0.00% |
2 | 25.00% |
3 | 37.50% |
4 | 50.00% |
5 | 59.38% |
6 | 67.19% |
7 | 73.44% |
8 | 78.52% |
9 | 82.62% |
10 | 85.94% |
15 | 95.13% |
20 | 98.31% |
25 | 99.41% |
30 | 99.80% |
35 | 99.93% |
40 | 99.98% |
45 | 99.99% |
As expected, the probability quickly climbs up as the number of flips increase, and asymptotically approaches certainty.