How many length-$n$ bitstrings containing $3$ consecutive $0$s and $4$ consecutive $1$s are there?
I thought that $a_n$ can be constructed in three ways:
The strings that contain both three consecutive $0s$ and four consecutive $1s$ and end up with a $0$. Hence, there are $a_{n-1}$ such strings.
The strings that contain both three consecutive $0s$ and four consecutive $1s$ and end up with a $1$. Hence , there are $a_{n-1}$ such strings.
The strings that end up with $\dots1111000$ or $\dots0001111$ . There are $2 \times 2^{n-7} = 2^{n-6}$ such strings.
As a result ,the number of length-$n$ strings that contain both three consecutive $0s$ and four consecutive $1s$ is equal to $$a_n = 2a_{n-1}+2^{n-6}$$ with $a_0, a_1,\dots, a_6 =0$ and $a_7 = 2$. Is this correct? If not, can you write correct closed formula?
Here's a recursive approach that might be useful.
Let $b_n$ be the number of length-$n$ bit strings that contain 3 consecutive 0s. By conditioning on the prefix 1, 01, 001, or 000, we find that $$b_n = \begin{cases} 0 &\text{if $n < 3$} \\ b_{n-1} + b_{n-2} + b_{n-3} + 2^{n-3} &\text{if $n \ge 3$} \end{cases} $$ Note that $b_n$ is https://oeis.org/A050231.
Similarly, let $c_n$ be the number of length-$n$ bit strings that contain 4 consecutive 1s. By conditioning on the prefix 0, 10, 110, 1110, or 1111, we find that $$c_n = \begin{cases} 0 &\text{if $n < 4$} \\ c_{n-1} + c_{n-2} + c_{n-3} + c_{n-4} + 2^{n-4} &\text{if $n \ge 4$} \end{cases} $$ Note that $c_n$ is https://oeis.org/A050232.
Now let $a^0_n,a^{00}_n,a^1_n,a^{11}_n,a^{111}_n$ be the number of length-$n$ bit strings that contain 3 consecutive 0s and 4 consecutive 1s and start with 0, 00, 1, 11, and 111, respectively. Then conditioning on whether the next bit is 0 or 1 yields \begin{align} a_n &= a^0_n + a^1_n \\ a^0_n &= a^{00}_n + a^1_{n-1} \\ a^{00}_n &= c_{n-3} + a^1_{n-2} \\ a^1_n &= a^0_{n-1} + a^{11}_n \\ a^{11}_n &= a^0_{n-2} + a^{111}_n \\ a^{111}_n &= a^0_{n-3} + b_{n-4} \end{align}