Here is a method to count which goes as much as possible with the one in the OP.
We face only the part with three consecutive zeros, want to get that claimed $107$. (The question does not come precise, i suppose this is the question.)
So let us be more precise in the counting.
For each bit string with at least one occurrence of $000$, named "good" for short in the sequel, we replace the first occurence of $000$ by a red zero, and we consider it as $\color{red}0\sim 000$.
So a good string generates a $6$-bit sting with exactly a red zero constrained to the following:
- $0\color{red}0$ is not a substring.
- $000*\color{red}0$ is not a substring. (Here $*$ is a placeholder for a word with letters $0,1$.)
Then the sum in the OP corresponds to the good strings with the first zero colored in red. But there are also further solutions! We collect them. If the red zero is not in $0\color{red}0$, then it is placed like this
$\color{blue}1\color{red}0\sim \color{blue}1000$. So this string must exist as a substring for all further solutions. We obtain the sum:
$$
\begin{aligned}
\sum_{1\le k\le 6}&\ (C(6,k)+(k-1)C(5,k))
\\
\qquad =&\ (C(6,1)+0\cdot C(5,1))\\
\qquad +&\ (C(6,2)+1\cdot C(5,2))\\
\qquad +&\ (C(6,3)+2\cdot C(5,3))\\
\qquad +&\ (C(6,4)+3\cdot C(5,4))\\
\qquad +&\ (C(6,5)+4\cdot C(5,5))\\
\qquad +&\ (C(6,6)+5\cdot C(5,6))\\
\qquad =&\ 63 + 49 = 112\ .
\end{aligned}
$$
where $C(6,k)$ corresponds to the choice of $\color{red}0$ at the first place (among the $k$ places), and
for each $C(5,k)$ we mark red one of the $k$ zeros not in the first position (which explains its factor $(k-1)$), and insert a blue $1$ in front of it ( - the reason for having available only $5$ places.)
The above sum is going beyond $107$, because we have neglected the second condition. The $5$ superfluous strings are of the shape $*000*\color{blue}1\color{red}0*$ of length six, so only a star is not empty, and the corresponding words are:
- $0000\color{blue}1\color{red}0$,
- $1000\color{blue}1\color{red}0$,
- $0001\color{blue}1\color{red}0$,
- $000\color{blue}1\color{red}00$,
- $000\color{blue}1\color{red}01$.
With the same argument, there are
$$
\sum_{1\le k\le 5}(C(5,k)+(k-1)C(4,k))
=
48
$$
possibilities for strings containing $1111$.
The number of $8$-bit strings containing both $000$ and $1111$, i.e. strings of the shape $*000*1111*$ or reversed is $8$, because for the matching pattern $*000*1111*$ we have only the following explicit possibilities:
- $00001111$,
- $10001111$,
- $00011111$,
- $00011110$.
Putting all together, there are 17+48-8 = 147 possibilities for a bit string of length $8$ to contain either $000$, or $1111$ (or both) as a substring.
Computer check, here sage:
def match000(v):
for k in range(len(v)-2):
if (0, 0, 0) == (v[k], v[k+1], v[k+2]):
return True
return False
def match1111(v):
for k in range(len(v)-3):
if (1, 1, 1, 1) == (v[k], v[k+1], v[k+2], v[k+3]):
return True
return False
count000 = 0
count1111 = 0
count = 0
for number in [0..2^8-1]:
v = number.digits(2, padto=8)
if match000(v):
count000 += 1
if match1111(v):
count1111 += 1
if match000(v) and match1111(v):
count += 1
print "Matches for 000 :: %s" % count000
print "Matches for 1111 :: %s" % count1111
print "Matches for both :: %s" % count
which delivers
Matches for 000 :: 107
Matches for 1111 :: 48
Matches for both :: 8