Number of strings of length 8 using ABCDEF that contain ABC? Here is my attempt to calculate the number of strings of length $8$ using $6$ characters (ABCDEF) which contain 'ABC'. Basically I wanted to see if my approach is correct or if there is a better way to calculate this.
Basically we consider ABC like an element by itself, and it can go:
ABC X X X X X
X ABC X X X X
X X ABC X X X
X X X ABC X X
X X X X ABC X
X X X X X ABC
Where the X represents another character. So we have $6$ rows and in each row there are $6^5$ possibilities (can choose between $6$ chars. and have $5$ spots), therefore we have $6^6$ combinations.
However there are repetitions, which are the following cases:
ABC ABC X X
ABC X ABC X
ABC X X ABC
X ABC ABC X
X ABC X ABC
X X ABC ABC
So we subtract these possibilities which are $6^3$ ($6 \cdot 6^2$ because there are $6$ rows and $2$ spots for $6$ chars in each row)
So we end up with $6^6 - 6^3$.
Thank you in advance.
 A: Your outcome is correct. This bruteforce calculation confirms it :D:
var count = 0;
for (let a0=0; a0<6; a0++)
for (let a1=0; a1<6; a1++)
for (let a2=0; a2<6; a2++)
for (let a3=0; a3<6; a3++)
for (let a4=0; a4<6; a4++)
for (let a5=0; a5<6; a5++)
for (let a6=0; a6<6; a6++)
for (let a7=0; a7<6; a7++) {
    let s =  a0+""+a1+""+a2+""+a3+""+a4+""+a5+""+a6+""+a7;
    if (s.indexOf("012")>=0) count++;
}
console.log(count);


46440

Another way to do this is to consider the state machine that tests whether a string contains the subsequence "ABC":

We can use this to calculate the probability of a 8 letter word containing the subsequence "ABC". It is equivalent to whether we reach the state "ABC" starting from the empty one in 8 steps. The matrix is
$$\left [
\begin{array}\\
\frac{5}{6} & \frac{1}{6} & 0 & 0 \\
\frac{4}{6} & \frac{1}{6} & \frac{1}{6} & 0 \\
\frac{4}{6} & \frac{1}{6} & 0 & \frac{1}{6}  \\
0 & 0 & 0 & 1 \\
\end{array}
\right ]
$$
Its eight power's top-right element gives the answer
(1/6[[5, 1, 0, 0], [4, 1, 1,0], [4, 1, 0, 1], [0,0,0,6]])^8

$$\frac{46440}{6^8}$$
