Binary strings with no three equal consecutive digits
Statement
Let be the number of binary strings of length that contain no three equal consecutive digits. Prove that , where and . Compute .
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 or . Conversely, the first digit and the sequence of run lengths determine the string.
So , where is the number of compositions of into parts and .
Recurrence for . Look at the last part: it is (the rest is a composition of ) or (the rest is a composition of ). Hence , with and . With , by induction.
Value. ; for , , so .
Check. A direct computer count gives for .
Lesson. Encode a string by its run lengths; restrictions on runs become restrictions on compositions.