0

I'm trying to find how many ways are there to build a binary word with 17 digits, so that the sequence '1111' won't appear. I don't really have an idea how to do it. I thought I could use inclusion-exclusion or recursion, but I'm searching for more straightforward solution. I'd really appreciate it if anyone could give me a lead.

Thank you very much!

  • 4
    This is the second time today this question has come up...what is the source? – lulu Jan 04 '20 at 21:27
  • 1
    connected (and interesting) : https://math.stackexchange.com/q/1193356, https://math.stackexchange.com/q/2163534 – Jean Marie Jan 05 '20 at 00:27

2 Answers2

2

Let us call a binary word acceptable if it satisfies your requirement that the sequence '1111' does not appear.
Let $a_n$ denote the number of acceptable strings of length $n$ that end with a $0$.
Let $b_n$ denote the number of acceptable strings of length $n$ that end with a _$1$.
Let $c_n$ denote the number of acceptable strings of length $n$ that end with a _$11$.
Let $d_n$ denote the number of acceptable strings of length $n$ that end with a _$111$.

Where '_' is either $0$ or empty.
It is clear, that the number of acceptable strings of length $n$ must be $a_n + b_n + c_n + d_n$. (Each acceptable string is counted once and exactly once in each of the four cases.)

Now, observe that we have the following recurrences for $n \ge 1$:

  • $a_{n+1} = a_n + b_n + c_n + d_n$. Take any acceptable string of length $n$ and add a $0$ at the end.
  • $b_{n+1} = a_n$. Take any acceptable string of length $n$ which does not end in a $1$ and add a $1$ at the end.
  • $c_{n+1} = b_n$. Similar argument as before.
  • $d_{n+1} = c_n$. Similar argument as before.

Note that $a_1 = b_1 = 1$ and $c_1 = d_1 = 0$ completely determine all values.

We can represent the above in matrix form as: $$\begin{bmatrix}a_{n+1}\\b_{n+1}\\c_{n+1}\\d_{n+1}\end{bmatrix} = \begin{bmatrix} 1 & 1 & 1 & 1\\1&0&0&0\\0&1&0&0\\0&0&1&0\end{bmatrix}\begin{bmatrix}a_{n}\\b_{n}\\c_{n}\\d_{n}\end{bmatrix}$$

Proceeding inductively gives us that $$\begin{bmatrix}a_{17}\\b_{17}\\c_{17}\\d_{17}\end{bmatrix} = \begin{bmatrix} 1 & 1 & 1 & 1\\1&0&0&0\\0&1&0&0\\0&0&1&0\end{bmatrix}^{16}\begin{bmatrix}a_1\\b_{1}\\c_{1}\\d_{1}\end{bmatrix} = \begin{bmatrix} 1 & 1 & 1 & 1\\1&0&0&0\\0&1&0&0\\0&0&1&0\end{bmatrix}^{16}\begin{bmatrix}1\\1\\0\\0\end{bmatrix}$$

The matrix exponentiation is fairly easy to calculate via a computer. The desired answer will be $a_{17} + b_{17} + c_{17} + d_{17}$.

Edit: it can be observed that the last sum is simply $a_{18}$ and one can carry out the matrix multiplication one step more.
In general, high powers of matrix can be calculated fairly easily using techniques such as exponentiation by squaring.

1

Here is a solution that has a strong similarity with the solution by @Aryaman Maithani but uses a straightforward method associated with a so-called "Markov chain" :

enter image description here

with 4 states with remaining hope (states (1),(2),(3),(4)), and last state where we fall if we have had four consecutive ones.

Let us start with state (1) where we are either waiting for the first figure or are in a situation where the last discovered digit is a zero :

  • either the new figure is a zero (probability 1/2) and we remain in this state (1)

  • or it is a one (probability 1/2) and we jump to state 2.

Being in state (2), which means that we have a single 1,

  • either the new figure is a zero (probability 1/2) and we jump back to state (1)

  • or it is a one and jump to state (3), etc.

How do we express the different moves in the automata ? By a matrix rendering the probability combinations (total probability law) applied to the initial state with a vector $(1,0,0,0,0)$ which means that, with probability 1, we are in state (1) right at the beginning of the "game". Taking $a:=1/2$, we have at the end of the $k$-th iteration, the following probabilities $p_1, p_2, p_3,p_4,p_{end}$ of being in states (1), (2), (3), (4) or "end" resp.:

$$\begin{pmatrix}p_1\\p_2\\p_3\\p_4\\p_{end}\end{pmatrix}=\left(\begin{array}{cccc|c} a& a&a&a&0\\a&0&0&0&0\\0&a&0&0&0\\0&0&a&0&0\\ \hline 0&0&0&a&1\end{array}\right)^k\begin{pmatrix} 1\\0\\0\\0\\0\end{pmatrix}\tag{1}$$

Can you "end it" (pun intended) from here knowing that a natural denominator you will find is $2^{17}$ (number of numbers with 17 decimal digits) and that you have to iterate $k$ times to finally find a fraction expressing the probability of unfavorable cases : therefore the numerator of this fraction counts the number of unfavorable cases...

Remarks :

  • The sum of every line of matrix (1) is equal to 1. One finds often the other convention (use transposition).

  • Formula (1) is completely analogous to the formula proposed in the other answer (the analogy is striking when you consider the upper left block).

Jean Marie
  • 81,803