A Coin Flip Game and Generalizations of Fibonacci Numbers: Abstract
A Coin Flip Game and Generalizations of Fibonacci Numbers: Abstract
JIA HUANG
Abstract. We study a game in which one keeps flipping a coin until a given finite string of heads
and tails occurs. We find the expected number of coin flips to end the game when the ending string
arXiv:2501.07463v1 [math.CO] 13 Jan 2025
consists of at most four maximal runs of heads or tails or alternates between heads and tails. This
leads to some summation identities involving certain generalizations of the Fibonacci numbers.
1. Introduction
In an X-post on March 16 2024, Daniel Litt [4] asked the following question (see also Chep-
lyaka [2]): If you flip a coin 100 times, will HT (a heads followed by a tails) occur more often than
HH (two heads in a row) or the other way around? Ekhad and Zeilberger [3] studied this and some
more general questions by symbolic computation. Segert [5] proved that it is more likely for HT to
outnumber HH when a coin is flipped at least three times and provided certain asymptotic results.
Basdevant, Hénard, Maurel-Ségala, and Singh [1] generalized this game by allowing two players
choosing two different strings of heads and tails with the same length.
While all the above research work and other related online discussions occurred in 2024, Simonson
discussed in a book published in 2022 [6, Ch. 2] a somewhat similar (but different) game in which
a carnie offers $5 to you while in a carnival and asks you to pay $n back, where n is the number
of times you flip a coin until you have two consecutive heads. Let E be the expected value of coin
flips to end this game. If the first flip gives a tail, then the expected value of flips to get two heads
in a row will be 1 + E. If the first flip gives a heads and the next is a tails, then the expected value
of flips will be 2 + E. If the first two flips both give a heads then the expected flips is 2. It follows
that E = 21 (1 + E) + 14 (2 + E) + 42 . This implies E = 6, so in average you will lose $1 each time
when you play this game.
There is another way to compute E. Let En be the number of outcomes from flipping a coin n
times such that the game will end right after n flips. This turns out to be the Fibonacci number
Fn−1 since En = n − 1 for n = 1, 2 and for n ≥ 3, if the first flip is a heads, then the next flip
must
P be a tails, son by induction, En = Fn−3 + Fn−2 = Fn−1 . It follows that the expected value of n
is ∞ n=1 nFn−1 /2 , which must equal 6. This can also be proved by standard generating function
technique, although Simonson did not address that, perhaps due to the scope of his book [6].
Simonson [6, Ch. 2] also mentioned that, since you will lose money eventually by playing the
first game a number of times, what if you are offered to switch roles with the carnie but using HT
instead of HH to end the game? Similarly as the above, one can show that the expected number of
flips to end this game is E = 4, so you should not get tricked again by the carnie. Interestingly, as
mentioned by Simonson [6, Ch. 2], although the expected number of coin flips to get HH is more
than the expected number of coin flips to get HT (and thus it is more likely for HT to outnumber
HH in a long run), it is equally likely to get HT or HH when either occurs, since it is a 1/2 chance
to get either a heads or a tails after a heads.
In this paper, we study a more general coin flip game which will be terminated right after the
first occurrence of a given finite string S of heads and tails. We call S the ending string of this
game and let E(S) denote the expected number of flips to end the game. For any integers k, ℓ ≥ 1,
we show that E(Hk ) = 2k+1 − 2 and E(Hk Tℓ ) = 2k+ℓ . This result implies not only that E(HH) = 6
and E(HT) = 4 as mentioned earlier but also the following identities:
∞
X k ∞
X k
nFn−1 nF n−2
= 2k+1 − 2 and = 2k+1 .
2n 2n
n=0 n=0
k
Here Fnk is the Fibonacci number of order k and F n is a variation of Fnk (see Section 3). We
also show that E(Hk Tℓ Hm ) = 2k+ℓ+m + 2min{k,m}+1 − 2 for any integers k, ℓ, m ≥ 1 and derive a
k
summation identity involving a two-parameter generalization of both Fnk and F n . Moreover, we
prove that for any integer k, ℓ, m, d ≥ 1,
(
k ℓ m d 2k+ℓ+m+d , if m < k or d > ℓ;
E(H T H T ) =
2k+ℓ+m+d + 2k+d , if m ≥ k and d ≤ ℓ.
This leads to a summation identity involving a different two-parameter generalization of the Fi-
bonacci numbers.
Thanks to the symmetry between heads and tails, we have settled all the cases when the ending
string of the coin flip game has at most four maximal runs of heads or tails, although it would need a
different type of symmetry argument (see Section 4) to explain the equalities E(Hk Tℓ ) = E(Tℓ Hk ),
E(Hk Tℓ Hm ) = E(Hm Tℓ Hk ), and E(Hk Tℓ Hm Td ) = E(Hd Tm Hℓ Tk ), all implied by our results
mentioned above. Lastly, for ending strings alternating between heads and tails, we obtain
k
X k
X
2i 22k+2 − 4 22k+1 − 2
k
E((HT) ) = 2 = and E((HT) k−1
H) = 22i−1 =
3 3
i=1 i=1
and derive some summation identities as well.
This paper is structured as follows. In Section 2 we determine E(S) when S has at most four
maximal runs of heads or tails or alternates between heads and tails. In Section 3 we derive
summation identities from our results in the last section. Finally, we ask some questions for future
research in Section 4.
where the second equality holds by Lemma 2.1. This implies that E = 2k+1 − 2.
Now let E = E(S), where S = Hk Tℓ . Then E = 12 E(S|H) + 12 E(S|T) and E(S|T) = E + 1, so
E(S|H) = E − 1. Suppose the first flip gives a heads. Then the (i + 1)th flip gives the first tails
for some integer i ≥ 1. If i < k then E(S|Hi T) = E + i + 1. Assume i ≥ k below. After the first
i flips (all heads) there will be a maximal run of j tails for some integer j ∈ {1, 2, . . . , ℓ}. If j < ℓ
then the next flip is a heads and E(S|Hi Tj H) = i + j + E(S|H) = E + i + j − 1. If j = ℓ then the
game ends and E(S|Hi Tℓ ) = i + ℓ. Thus
k−1 ∞ ℓ−1
E − 1 X E + i + 1 X X E + i + j − 1 i + ℓ
= + + i+ℓ
2 2i+1 2i+j+1 2
i=1 i=k j=1
∞
E E 3 k+2 X 1 E E i+1 i+ℓ i+ℓ
= − k+ − k + − ℓ + i+1 − i+ℓ + i+ℓ
2 2 2 2 2i 2 2 2 2 2
i=k
E E 3 k+2 E E k+2
= − k + − k + k − k+ℓ−1 + k .
2 2 2 2 2 2 2
Here the second and third equalities hold by Lemma 2.1. It follows that E = 2k+ℓ .
To tackle the cases when S consists of more than two maximal runs of heads or tails, we define
E(S|R) to be the expected number of flips to obtain S given that the first r flips produce R, where
R is a string of heads and tails with length r, and develop some lemmas.
Lemma 2.3. If the ending string S of the coin flip game begins with a string R of length r, then
E(S) = E(R) + E(S|R) − r.
Proof. If S occurs then R must occur first. It takes E(R) flips in average to obtain the first
occurrence of R, and all the flips before that will not affect when the game ends. It will then take
E(S|R) − r extra flips in average to obtain S. Thus E(S) = E(R) + E(S|R) − r.
Lemma 2.4. The following holds for E(S), where S begins with a maximal run of k ≥ 1 heads.
• If i < k then E(S|Hi T) = E + i + 1 and E(S|Hi ) = E + i + 2 − 2i+1 .
• If i ≥ k then E(S|Hi T) = E + i + 1 − 2k+1 and E(S|Hi ) = E + i + 2 − 2k+1 .
Proof. Let E = E(S). For i < k, if the first i + 1 flips give Hi T then the game is reset, so
E(S|Hi T) = E + i + 1. For i ≤ k, Lemma 2.3 implies that
E(S|Hi ) = E + i − E(Hi ) = E + i + 2 − 2i+1 ,
which can also be proved by using E(S|Hi ) = 2E(S|Hi−1 ) − E(S|Hi−1 T) and induction on i. For
i > k we have
E(S|Hi ) = i − k + E(S|Hk ) = E + i + 2 − 2k+1 .
Then for i ≥ k we have
E(S|Hi T) = 2E(S|Hi ) − E(S|Hi+1 ) = 2(E + i + 2 − 2k+1 ) − (E + i + 3 − 2k+1 ) = E + i + 1 − 2k+1 .
Before any new result, we use the above lemmas to give a more concise proof for Theorem 2.2.
Another proof for Theorem 2.2. First let E = E(S), where S = Hk for some k ≥ 1. By Lemma 2.4,
E(S|Hk−1 ) = E + k + 1 − 2k . Also, E(S|Hk−1 ) = 12 (E + k) + k2 = 21 E + k. Thus E = 2k+2 − 2.
Now let E = E(S), where S = Hk Tℓ for some integers k, ℓ ≥ 1. If ℓ = 1 then by Lemma 2.4,
k + 1 = E(S|Hk T) = E + k + 1 − 2k+1 , so E = 2k+1 . Assume ℓ ≥ 2 below. By Lemma 2.3,
E = E(Hk Tℓ−1 ) + E(S|Hk Tℓ−1 ) − k − ℓ + 1. Since E(S|H) = E − 1 by Lemma 2.4, we have
E(S|Hk Tℓ−1 ) = 12 (E + k + ℓ − 2) + 21 (k + ℓ). Thus E = 2E(Hk Tℓ−1 ). By induction, E = 2k+ℓ .
Similarly to Theorem 2.2, we now determine E(S) when S consists of three maximal runs of
heads or tails and provide two proofs for our result.
4 JIA HUANG
E+k−1 ℓ E(S|Hk Tℓ H)
=E +k−1− + 2 − + .
2ℓ 2ℓ 2ℓ
Thus E(S|Hk Tℓ H) = E + k + ℓ − 1 − 2k+ℓ+1 . Then for i = 1, . . . , d − 1 we have
(
k ℓ m i E + k + ℓ + m + i − 1, if m < k or i 6= ℓ;
E(S|H T H T H) = k+ℓ+1
E +k+ℓ+m+i−1−2 , if m ≥ k and i = ℓ.
Therefore, we can solve for E from the above and obtain the desired result.
We also have E(Hk Tℓ Hm Td−1 ) = E(Hk Tℓ Hm ) = 2k+ℓ+m + 2min{k,m}+1 − 2 by Theorem 2.5. Thus
(
2k+ℓ+m+1 , if m < k;
E= k+ℓ+m+1 k+1
2 + 2 , if m ≥ k.
Now assume d ≥ 2. We have E(S|Hk Tℓ H) = E + k + ℓ − 1 − 2k+ℓ+1 from the previous proof and
E(S|H) = E − 1 by Lemma 2.4. Thus
(
E + k + ℓ + m + d − 2 − 2k+ℓ+1 , if m ≥ k and d = ℓ + 1;
E(S|Hk Tℓ Hm Td−1 H) =
E + k + ℓ + m + d − 2, if m < k or d 6= ℓ + 1.
Finally, we find E(S) when S is a finite string alternating between heads and tails.
Theorem 2.8. For any integer k ≥ 1, we have
k
X k
X
22k+2 − 4 22k+1 − 2
E((HT)k ) = 22i = and E((HT)k−1 H) = 22i−1 = .
3 3
i=1 i=1
6 JIA HUANG
Here En (S) denotes the number of strings consisting of a total of n heads and tails such that S
occurs only at the end. Also define En (S|R) to be the number of strings consisting of a total of n
heads and tails with R occurring at the beginning (possibly elsewhere) and S occurring only at the
end. The following lemma will be useful when we compute En (S).
Lemma 3.1. Suppose k, ℓ, m ≥ 1 are integers. Let En = En (S).
(i) If S begins with Hk , then En (S|Hi ) = En − En−1 − · · · − En−i for i = 1, . . . , k.
(ii) If S begins with Hk T, then En (S|Hk T) = En − 2En−1 + En−k−1 .
(iii) If S begins with Hk Tℓ H, then En (S|Hk Tℓ H) = En − 2En−1 + En−k−ℓ − En−k−ℓ−1 .
Proof. (i) For i = 1, . . . , k, we have En (S|Hi−1 T) = En−i as the occurrence of Hi−1 T at the
beginning does not affect when S will occur, and this implies by induction that
En (S|Hi ) = En (S|Hi−1 ) − En (S|Hi−1 T) = En − En−1 − · · · − En−i .
(ii) We have En (S|Hk T) = En (S|Hk ) − En (S|Hk+1 ) and En (S|Hk+1 ) = En−1 (S|Hk ). Since the
result from (i) is still valid here, it follows that En (S|Hk T) = En − 2En−1 + En−k−1 .
(iii) In this case we have an alternative way to compute En (S|Hk T):
ℓ
X
k
En (S|H T) = En (S|Hk Ti H) + En (S|Hk Tℓ+1 )
i=1
ℓ−1
X
= En−k−i (S|H) + En (S|Hk Tℓ H) + En−k−ℓ−1
i=1
ℓ−1
X
= (En−k−i − En−k−i−1 ) + En (S|Hk Tℓ H) + En−k−ℓ−1
i=1
=En−k−1 − En−k−ℓ + En (S|Hk Tℓ H) + En−k−ℓ−1.
Comparing this with (ii) gives the desired result.
A COIN FLIP GAME AND GENERALIZATIONS OF FIBONACCI NUMBERS 7
Recall that the Fibonacci number of order k is defined by Fnk = 0 for n < k − 1, Fnk = 1 for
n = k − 1, and Fnk = Fn−1
k k
+ Fn−2 k
+ · · · + Fn−k for n ≥ k. We have Fn,1 = 1 for n ≥ 0, Fn,2 = Fn
is the well-known Fibonacci number [7, A000045], Fn,3 is the tribonacci number [7, A000073], Fn,4
is the tetranacci number [7, A000078], and so on.
k k
We define a variation of the Fibonacci number of order k by F n = 0 for n < k − 1, F n = 1 for
k k k k
n = k − 1, and F n = F n−1 + F n−2 + · · · + F n−k + 1 for n ≥ k. By a direct argument or using the
generating functions given in Remark 3.4, one can show that the above recurrence is equivalent to
k k k
either F n = 2F n−1 − F n−k−1 or
k k k
F n = F n−1 + Fnk = F n−2 + Fn−1
k
+ Fnk = · · · = F0k + F1k + · · · + Fnk .
1 2 3 4
Special cases include F n = n + 1, F n = Fn+2 − 1 [7, A000071], F n [7, A008937], F n [7, A107066],
and so on.
We now compute En (S) when S consists of at most two maximal runs of heads or tails.
k+ℓ−1
Proposition 3.2. For any integers k, ℓ ≥ 1, we have En (Hk ) = Fn−1
k and En (Hk Tℓ ) = F n−2 .
Proof. First, let En = En (S), where S = Hk . Then En = 0 if n < k and En = 1 if n = k. For
n > k we have 0 = En (S|Hk ) = En − En−1 − · · · − En−k by Lemma 3.1 (i). Thus En = Fn−1
k .
Proof. Taking S = Hk
in Eq. (1) gives the first desired identity. Taking S = Hk Tℓ in Eq. (1) gives
X∞ k+ℓ−1
nF n−2
n
= E(Hk Tℓ ) = 2k+ℓ , which is equivalent to the second desired identity.
n=0
2
P k xn . Then
Remark 3.4. We can prove Corollary 3.3 by generating functions. Let f (x) = n≥0 Fn−1
k
XX X
xf (x) + x2 f (x) + · · · + xk f (x) = k
Fn−i xn+1 = Fnk xn = f (x) − xk .
n≥k i=1 n≥k
xk 1
Thus f (x) = 1−x−x2 −···−xk
. We can then substitute x =into xf ′ (x) and simplify the result by
2
P k
Lemma 2.1 to obtain the first identity in Corollary 3.3. Similarly, f (x) = n≥0 F n−2 xn satisfies
k
XX X
2 k k k xk+1
xf (x) + x f (x) + · · · + x f (x) = F n−i xn+2 = (F n − 1)xn+2 = f (x) − .
1−x
n≥k i=1 n≥k
xk+1 xk+1 1
Thus f (x) = (1−x)(1−x−x2 −···−xk ) = 1−2x+xk+1
. Substituting x = 2 into xf ′ (x) gives the second
identity in Corollary 3.3.
8 JIA HUANG
k
Next, we introduce a two-parameter generalization of both Fnk and F n . Let Fnk,m = 0 for
n < k + m − 1, Fnk,m = 1 for n = k + m − 1, and for n ≥ k + m,
m
X
k,m k,m k,m
Fnk,m = 2Fn−1 − Fn−k−1 + Fn−k−i−1 .
i=1
By Lemma 2.4 (iii), we have the following, where the last term is zero since n > k + ℓ + m:
m−1
X
En = 2En−1 − En−k−ℓ + En−k−ℓ−1 + En (S|Hk Tℓ Hi T) + En (S|Hk Tℓ Hm ).
i=1
Proposition 3.5 suggests an identity involving Fnk,m , which can be proved by generating functions
to avoid the restriction on the relative sizes of k and m.
k,m
X nFn−2
Corollary 3.6. For any integers k, m ≥ 1 we have = 2k+m+1 + 2m+1 − 2.
2n
n≥1
1
Evaluating x times the derivative of the above generating function at x = 2 and using Lemma 2.1
to simplify the result we obtain the desired identity.
Note that one can recover Corollary 3.3 from Corollary 3.6 by taking k = 0 or m = 0.
Next, we introduce another two-parameter generalization of the Fibonacci numbers by defining
Fenk,m = 0 for n < k + m − 1, Fenk,m = 1 for n = k + m − 1, and for n > k + m − 1,
k,m k,m k,m k,m
Fenk,m = 2Fen−1 − Fen−k−1 + 2Fen−k−2 − Fen−k−m−2 .
d−1
X
En (S|Hk Tℓ Hm ) = En (S|Hk Tℓ Hm+1 ) + En (S|Hk Tℓ Hm Ti H) + En (S|Hk Tℓ Hm Td ).
i=1
If m < k then using En (S|Hi ) = En − En−1 − · · · − En−i for i = 1, . . . , k from Lemma 3.1 we obtain
m+1
X d−1
X
k ℓ m
En (S|H T H ) =En−k−ℓ − En−k−ℓ−i + (En−k−ℓ−m−i − En−k−ℓ−m−i−1 )
i=1 i=1
m
X
=En−k−ℓ − En−k−ℓ−i − En−k−ℓ−m−d ,
i=1
and adding this to the right hand side of Eq. (2) in the case m < k gives En = 2En−1 −En−k−ℓ−m−d .
Similarly, if m ≥ k and d ≤ ℓ then we can add
d−1
X
k ℓ m k
En (S|H T H ) = En−ℓ−m−1 (S|H ) + En−k−ℓ−m−i (S|H)
i=1
k
X
= En−ℓ−m−1 − En−ℓ−m−i − En−k−ℓ−m−d
i=2
to the right hand side of Eq. (2) in the case m ≥ k (the two cases there coincide when m = k) gives
∞
X X∞
nG2k n 22k+2 − 4 nGn2k−1 22k+1 − 2
Corollary 3.10. For any integer k ≥ 1, = and = .
n=0
2n 3 n=0
2n 3
Remark 3.11. We can prove Corollary 3.10 by generating functions. For any integer k ≥ 1, we have
x2k x2k (1−x2 ) x2k (1+x)
X∞
1−Pk (2x2i−1 −x2i ) = 1−2x+2x2k+1 −x2k+2 = 1−P2k xi +x2k+1 , if s = 2k;
s n i=1 i=1
Gn x =
Pk−1 x2k−1 x2k−1 (1−x2 ) x2k−1 (1+x)
n=0 2i−1 2i 2k−1
= 1−2x+x 2k−1 −x2k +x2k+1 = P2k−2 i 2k , if s = 2k − 1.
1− i=1 (2x −x )−x 1− i=1 x −x
1
We then take the derivative, multiply by x and substitute in x = 2 to obtain the desired identities.
4. Questions
In this paper, we determine the expected number of coin flips to produce a given finite string
which either has at most four maximal runs of heads or tails or alternates between heads and tails;
the result is always a sum of powers of 2. It would be nice to provide an intuitive explanation for
this. We also have the following conjecture for an arbitrary ending string based on our result.
Conjecture 4.1. Suppose S ∈ / {Hk , Tk } is a string consisting of a total of s heads and tails. Then
E(S) equals 2s possibly plus some lower positive powers of 2, so asymptotically, E(S) is about 2s .
Moreover, we have E(Hk Tℓ ) = E(Hℓ Tk ) by Theorem 2.2, E(Hk Tℓ Hm ) = E(Hm Tℓ Hk ) by Theo-
rem 2.5, and E(Hk Tℓ Hm Td ) = E(Hd Tm Hℓ Tk ) by Theorem 2.7. This leads to another conjecture.
Conjecture 4.2. If S ′ is the reversal of an ending string S, then E(S) = E(S ′ ).
We do not have a rigorous proof for the above conjecture, but here is an intuitive argument: if
one flips a coin a large number of times, then E(S) is the average distance between an occurrence
of S and the next, but reading the outcomes backward, we have the same average distance between
an occurrence of S ′ and the next, so E(S ′ ) = E(S).
One way to extend our work is to study a similar game using a die instead of a coin. For
example, if E is the expected number of times to throw a die with c faces marked 1, . . . , c to obtain
Xk
(c − 1)(E + i) k
a run of k ones, then E = i
+ k , and solving this equation with the help of the
c c
i=1
k
X i c (c − 1)k + c ck+1 − c
formula = − yields E = . Taking c = 2 recovers our result
ci (c − 1)2 (c − 1)2 · ck c−1
i=1
E(Hk ) = 2k+1 − 2 in Theorem 2.2.
One could also try to extend work of Ekhad and Zeilberger [3] and work of Segert [5] by inves-
tigating how often those strings of heads and tails discussed in this paper will occur when flipping
a coin a large number of times. Some of the results in this paper might be helpful in a similar way
as how comparing E(HH) = 6 with E(HT) = 4 at least intuitively explains why HT outnumbers
HH in the long run.
References
[1] A-L. Basdevant, O. Hénard, É. Maurel-Ségala, and A. Singh, On cases where Litt’s game is fair, arXiv:2406.20049
[math.CO].
[2] R. Cheplyaka, Alice and Bob flipping coins puzzle, March 18, 2024.
https://ro-che.info/articles/2024-03-18-alice-bob-coin-flipping.
[3] S. B. Ekhad and D. Zeilberger, How to answer questions of the type: if you toss a coin n times, how likely is
HH to show up more than HT? The personal Journal of Shalosh B. Ekhad and Doron Zeilberger, May 20, 2024.
https://sites.math.rutgers.edu/~ zeilberg/mamarim/mamarimhtml/litt.html
[4] D. Litt, X-post, March 16 2024, https://x.com/littmath/status/1769044719034647001.
12 JIA HUANG
[5] S. Segert, A proof that HT is more likely to outnumber HH than vice versa in a string of n coin flips,
arXiv:2405.16660 [math.CO].
[6] S. Simonson, Looking for Math in All the Wrong Places: Math in Real Life, AMS/MAA Spectrum Vol. 104,
American Mathematical Society, 2022.
[7] N. J. A. Sloane et al., The On-Line Encyclopedia of Integer Sequences, OEIS Foundation Inc., https://oeis.org.