THE “ABRACADABRA” PROBLEM
FRANCESCO CARAVENNA
Abstract. We present a detailed solution of Exercise E10.6 in [Wil91]: in a random
sequence of letters, drawn independently and uniformly from the English alphabet, the
expected time for the first appearance of the word “ABRACADABRA” is 2611 + 264 + 26.
We adopt the conventions N := {1, 2, 3, . . .} and N0 := N ∪ {0}.
1. Formulation of the problem
Let (Ui )i∈N denote random letters drawn independently and uniformly from the English
alphabet. More precisely, we assume that (Ui )i∈N are independent and identically distributed
random variables, uniformly distributed in the set E := {A, B, C, D, . . . , X, Y, Z}, defined
on some probability space (Ω, A, P). For m, n ∈ N with m ≤ n, we use U[m,n] as a shortcut
for the vector (Um , Um+1 , . . . , Un ).
Define τ as the random time in which the word “ABRACADABRA” first appears:
τ := min{n ∈ N, n ≥ 11 : U[n−10,n] = ABRACADABRA} ,
(1.1)
with the convention min ∅ := +∞. Our goal is to prove the following result.
Theorem 1. E[τ ] = 2611 + 264 + 26.
2. Strategy
The proof is based on martingales. Let (Fn )n∈N0 be the natural filtration of (Ui )i∈N , i.e.,
F0 := {∅, Ω} and Fn := σ(U1 , . . . , Un ). We are going to prove the following results.
Proposition 2. τ is a stopping time with E[τ ] < ∞.
Proposition 3. There exists a martingale M = (Mn )n∈N0 such that:
(1) M0 = 0 and Mτ = 2611 + 264 + 26 − τ ;
(2) M has bounded increments: ∃C ∈ (0, ∞) such that |Mn+1 − Mn | ≤ C, for all n ∈ N0 .
Let us recall (a special case of) Doob’s optional sampling theorem, cf. [Wil91, §10.10].
Theorem 4. If M = (Mn )n∈N0 is a martingale with bounded increments and τ is a stopping
time with finite mean, then E[Mτ ] = E[M0 ].
Combining this with Propositions 2 and 3, one obtains immediately the proof of Theorem 1.
Date: April 10, 2015.
1
2
FRANCESCO CARAVENNA
3. Proof of Proposition 2
Recall that τ is a stopping time if and only if {τ ≤ n} ∈ Fn for every n ∈ N0 . Note that
{τ ≤ n} = ∅ if n ≤ 10, while for n ≥ 11
{τ ≤ n} =
n
[
{U[i−10,i] = ABRACADABRA},
i=11
which shows that the event {τ ≤ n} is in Fn (it is expressed as a function of U1 , U2 , . . . , Un ).
To prove that E[τ ] < ∞, we argue as in [Wil91, §10.11; Exercise E10.5].
Lemma 5. For a positive random variable τ , in order to have E[τ ] < ∞ it is sufficient that
∃N ∈ N, ε > 0 :
P(τ ≤ n + N | τ > n) ≥ ε
∀n ∈ N0 .
(3.1)
This result is proved in Appendix A below. In order to apply it, let An be the event that
the word “ABRACADABRA” appears (not necessarily for the first time!) at time n + 11:
An := {U[n+1,n+11] = ABRACADABRA}.
By assumption Ui are independent and uniformly chosen letters, hence
1
1
P(An ) = p11 > 0,
where
p := = .
E
26
Since An ⊆ {τ ≤ n + 11}, we have P(τ ≤ n + 11 | τ > n) ≥ P(An | τ > n) for every n ∈ N.
However the events An and {τ > n} are independent (An is a function of U[n+1,n+11] , while
{τ > n} = {τ ≤ n}c ∈ Fn is a function of U[1,n] ), hence P(An | τ > n) = P(An ). Thus
P(τ ≤ n + 11 | τ > n) ≥ P(An ) = p11 ,
i.e. relation (3.1) holds with N = 11 and ε = p11 . It follows by Lemma 5 that E[τ ] < ∞. 4. Proof of Proposition 3
The required martingale M = (Mn )n∈N0 will be constructed as the total net gain of a
suitable family of gamblers, built as follows.
At time 0 a first gambler enters the game, with an initial capital of 1e. She bets on the
event that the first letter U1 is A (the first letter of the word “ABRACADABRA”). If she
loses, her capital at time 1 drops to 0e and she stops playing (i.e. her capital will stay 0e
at all later times). On the other hand, if she wins, her capital at time 1 becomes 26e and
she goes on playing, betting on the event that the second letter U2 is B (the second letter of
“ABRACADABRA”). If she loses, her capital at time 2 is 0e and she stops playing, while if
she wins, her capital at time 2 equals (26)2 e and she goes on, betting on the event that the
third letter U3 is R (the third letter of “ABRACADABRA”), and so on, until time 11.
The gambler’s capital at time 11 is either (26)11 e, if the letters U[1,11] have formed exactly
the word “ABRACADABRA”, or 0e otherwise. In any case, the gambler stops playing after
time 11, hence her capital will stay constant at all later times.
Let us denote by xi be the i-th letter of the word “ABRACADABRA”, for 1 ≤ i ≤ 11 (so
that x1 = A, x2 = B, x3 = R, . . . , x11 = A). The capital (in e) of this first gambler at time
n is then given by the process (Kn )n∈N0 defined as follows:
if n = 0
1
Kn := Kn−1 · 26 1{Un =xn } if 1 ≤ n ≤ 11 .
K11
if n ≥ 12
THE “ABRACADABRA” PROBLEM
3
(Note that if Kn−1 = 0, then Kn = 0 irrespectively of Un , as described above.)
Now a second gambler arrives, playing the same game, but with one time unit of delay. Her
initial capital stays 1e at time 0 and at time 1, then she bets on the event that U2 = x1 = A:
if she loses, her capital at time 2 is 0e and she stops playing, while if she wins, her capital
at time 2 is 26e and she goes on playing, betting on the event that U3 = x2 = B, etc. At
time 12, the second gambler’s capital will be either (26)11 e or 0e, according to whether the
letters U[2,12] have formed precisely the word “ABRACADABRA” or not. At this point she
stops playing and her capital stays constant at all later times.
Generalizing the picture, imagine that for each j ∈ N there is a j-th gambler with an
initial capital of 1e, who starts playing just before time j, betting on the event that Uj = x1 ,
then (if she wins) on Uj+1 = x2 , . . . , and finally (if she has won all the previous bets) on
Uj+10 = x11 . After time j + 10 the gambler stops playing and her capital stays constant.
(j)
Denoting by Kn the capital (in e) of the j-th gambler at time n, for n ∈ N0 , we have
if n < j
1
(j)
(j)
Kn := Kn−1 · 26 1{Un =x(n−j)+1 } if j ≤ n ≤ j + 10 .
(4.1)
(j)
Kj+10
if n > j + 10
We can finally define the process we are looking for, that will be shown to be a martingale:
!
n
n
X
X
(j)
(j)
(j)
M0 := 0,
Mn :=
(Kn − K0 ) =
Kn
− n.
(4.2)
j=1
j=1
(j)
(j)
Thus Mn is the sum of the net gains Kn − K0 of the first n gamblers at time n.† For the
(j)
equality in (4.2), recall that K0 = 1 for all j ∈ N.
Lemma 6. For τ defined as in (1.1), one has Mτ = (26)11 + (26)4 + 26 − τ .
Proof. We need to evaluate
Mτ =
τ
X
!
Kτ(j)
− τ.
j=1
(j)
Recall that Kτ is the capital at time τ of the gambler who starts betting just before time
(j)
j. It suffices to show that Kτ = 0 except for j ∈ {τ − 10, τ − 3, τ }, for which
Kτ(τ −10) = (26)11 ,
Kτ(τ −3) = (26)4 ,
Kτ(τ ) = 26.
Since the complete word “ABRACADABRA” appears at time τ , the gambler who started
(τ −10)
playing just before time τ − 10 has a capital of (26)11 , i.e. Kτ
= (26)11 . The gambler
(τ −3)
who started playing just before time τ − 3 has a capital Kτ
= (26)4 , because the last
four letters of “ABRACADABRA” are “ABRA” and coincide with the first four letters of
that word. Analogously, since the last letter “A” is the same as the first letter, the gambler
(τ )
who started playing just before time τ has won his first bet and his capital is Kτ = 26.
Finally, for all j 6∈ {τ − 10, τ − 3, τ } all gamblers have lost at least one bet and their
(j)
capital is Kτ = 0, because τ is the first time the word “ABRACADABRA” appears. †
We could have equivalently summed the net gains of all gamblers, defining Mn :=
because
(j)
Kn
=
(j)
K0
for j > n.
P∞
(j)
j=1 (Kn
(j)
− K0 ),
4
FRANCESCO CARAVENNA
To complete the proof of Proposition 3, it remains to show that M = (Mn )n∈N0 is a
martingale with bounded increments. We start looking at the capital processes.
(j)
Lemma 7. For every fixed j ∈ N, the capital process (Kn )n∈N0 is a martingale.
(j)
(j)
Proof. We argue for fixed j ∈ N. Plainly, K0 = 1 is F0 -measurable. By (4.1), Kn is a
(j)
(j)
measurable function of Kn−1 and Un , assuming inductively that Kn−1 is Fn−1 -measurable,
(j)
(j)
it follows that Kn is Fn -measurable. This shows that (Kn )n∈N0 is an adapted process.
(j)
(j)
(j)
Since |Kn | ≤ 26|Kn−1 | by (4.1), it follows inductively that |Kn | ≤ 26n for all n ∈ N,
(j)
hence the random variables |Kn | are bounded (and, in particular, integrable).
(j)
(j)
Finally, the relation E[Kn |Fn−1 ] = Kn−1 is trivially satisfied if n < j or if n > j + 10,
while for n ∈ {j, . . . , j + 10}, again by (4.1),
(j)
(j)
(j)
E[Kn(j) |Fn−1 ] = E[Kn−1 · 26 1{Un =x(n−j)+1 } |Fn−1 ] = Kn−1 · 26 P(Un = x(n−j)+1 ) = Kn−1 ,
because Un is independent of Fn−1 and P(Un = a) =
1
26
for every a ∈ E.
(j)
Lemma 8. The capital processes (Kn )n∈N0 have uniformly bounded increments:
(j)
|Kn(j) − Kn−1 | ≤ 2511 ,
(j)
∀j, n ∈ N.
(4.3)
(j)
Proof. One has |Kn −Kn−1 | = 0 if n < j or n > j +10, by (4.1), while for n ∈ {j, . . . , j +10}
(j)
(j)
(j)
|Kn(j) − Kn−1 | ≤ |26 1{Un =x(n−j)+1 } − 1||Kn−1 | ≤ 25 |Kn−1 | .
(j)
Since Kj−1 = 1, relation (4.3) follows.
We can finally show that M is a martingale. Note that Mn is Fn -measurable and in L1 ,
(j)
for every n ∈ N, because by (4.2) Mn is a finite sum of Kn , each of which is Fn -measurable
and in L1 by Lemma 7. Furthermore, again by (4.2), for all n ∈ N we can write
n
n
X
X
(j)
(j)
E[Mn |Fn−1 ] =
E[Kn |Fn−1 ] − n =
Kn−1 − n.
j=1
(j)
j=1
(n)
However for j = n we have Kn−1 = Kn−1 = 1 by definition, cf. (4.1), hence
E[Mn |Fn−1 ] =
n−1
X
(j)
Kn−1 + 1 − n =
j=1
n−1
X
(j)
Kn−1 − (n − 1) = Mn−1 .
j=1
This shows that M is a martingale. Finally, for all n ∈ N
n−1
X
n
n
X
X (j)
(j) (j)
Mn − Mn−1 =
Kn − n −
Kn−1 − (n − 1) =
Kn(j) − Kn−1 ,
j=1
j=1
(j)
j=1
(n)
again because for j = n we have Kn−1 = Kn−1 = 1. Now observe that, again by (4.1), for
(j)
(j)
(j)
n ≥ j + 11 one has Kn = Kn−1 = Kj+10 , hence
X
n
X
n
(j)
(j)
(j)
Kn − K (j) ≤ 11 · 2511 ,
|Mn − Mn−1 | = Kn − Kn−1 ≤
n−1
j=n−10
j=n−10
having applied (4.3). This shows that M has bounded increments, completing the proof. THE “ABRACADABRA” PROBLEM
5
Appendix A. Proof of Lemma 5
The assumptions imply that
P(τ > `N ) ≤ (1 − ε)`
∀` ∈ N0 ,
(A.1)
as we show below. We are going to use the formula
Z ∞
P(τ > t) dt,
E[τ ] =
(A.2)
0
valid for every random variable τ taking values in [0, ∞].† Breaking up the integral in the
sub-intervals [`N, (` + 1)N ], with ` ∈ N0 , since P(τ > t) ≤ P(τ > `N ) for t ≥ `N , we get
Z (`+1)N
X Z (`+1)N
X
X
E[τ ] =
P(τ > t) dt ≤
P(τ > `N )
1 dt ≤
(1 − ε)` N
`∈N0
`N
`∈N0
`N
`∈N0
N
N
=
< ∞,
1 − (1 − ε)
ε
P
1
having applied the geometric series n∈N0 q n = 1−q
. This shows that E[τ ] < ∞, as required.
It remains to prove (A.1), which we do by induction. For ` = 0 there is nothing to prove.
For every ` ∈ N0 , since {τ > (` + 1)N } ⊆ {τ > `N }, we can write
=
P(τ > (` + 1)N ) = P(τ > (` + 1)N, τ > `N )
= P(τ > `N ) P(τ > (` + 1)N | τ > `N ) .
(A.3)
The induction step yields P(τ > `N ) ≤ (1 − ε)`, while assumption (3.1) gives
P(τ > n + N | τ > n) ≤ (1 − ε) ,
∀n ∈ N .
Choosing n = `N yields P(τ > (` + 1)N | τ > `N ) ≤ (1 − ε), which plugged into (A.3) yields
P(τ > (` + 1)N ) ≤ (1 − ε)`+1 , as required.
References
[Wil91] D. Williams (1991), Probability with martingales, Cambridge University Press
Dipartimento di Matematica e Applicazioni, Università degli Studi di Milano-Bicocca, via
Cozzi 55, 20125 Milano, Italy
E-mail address: [email protected]
RT
R∞
R∞
For every T ∈ [0, ∞] one has T = 0 1 dt = 0 1{T ≥t} dt, hence τ (ω) = 0 1{τ (ω)>t} dt for every
random variable τ taking values in [0, ∞]. Taking expectations of both sides and exchanging the expectation
with the integral (which is justified by Fubini-Tonelli, thanks to positivity) one obtains (A.2).
†
© Copyright 2026 Paperzz