Maths WorkshopMaths problems with full solutions
Exercise 1247Combinatorics › Counting principlesM1Added 4 Nov 2026

Binary strings with no three equal consecutive digits

#recurrences#Fibonacci numbers#compositions#binary strings

Statement

Let ana_n be the number of binary strings of length nn that contain no three equal consecutive digits. Prove that an=2Fn+1a_n=2F_{n+1}, where F1=F2=1F_1=F_2=1 and Fk+1=Fk+Fk−1F_{k+1}=F_k+F_{k-1}. Compute a10a_{10}.

Hint

A string is determined by its first digit and by the lengths of its maximal blocks of equal digits. What values can a block length take?

Show solutionHide solution

Solution

Blocks. Split a string into maximal runs of equal digits. The condition says each run has length 11 or 22. Conversely, the first digit and the sequence of run lengths determine the string.

So an=2cna_n=2c_n, where cnc_n is the number of compositions of nn into parts 11 and 22.

Recurrence for cnc_n. Look at the last part: it is 11 (the rest is a composition of n−1n-1) or 22 (the rest is a composition of n−2n-2). Hence cn=cn−1+cn−2c_n=c_{n-1}+c_{n-2}, with c1=1c_1=1 and c2=2c_2=2. With F1=F2=1F_1=F_2=1, cn=Fn+1c_n=F_{n+1} by induction.

Value. an=2Fn+1a_n=2F_{n+1}; for n=10n=10, F11=89F_{11}=89, so a10=178a_{10}=178.

Check. A direct computer count gives 2,4,6,10,16,26,42,68,110,1782,4,6,10,16,26,42,68,110,178 for n=1,…,10n=1,\dots,10.

Lesson. Encode a string by its run lengths; restrictions on runs become restrictions on compositions.