I agree with Calvin Lin's comment. That is, the starter enumeration is $4^n$.
Also, I reject the Inclusion-Exclusion approach as being to unwieldy, given that a formula is required for the generic value of $n$. For a small explicit value of $n$, I would have more strongly considered Inclusion-Exclusion.
Highjacking the insight from the comment of Thomas Andrews, I will use recursion.
For $n=2$, the number of satisfying words is $(4^2) - 2.$
To investigate the use of recursion, I must enumerate how many of the $(14)$ satisfying $2$-letter words end in $a$ or $b$, and how many do not.
If the last character is $a$ or $b$, then, in the satisfying word, there are 3 choices for the first character. Therefore, there are $6$ satisfying $2$-letter words that end in $a$ or $b$. Similarly, if the last character is $c$ or $d$, then the first character is unconstrained. Therefore, there are $8$ satisfying $2$-letter words that end in $c$ or $d$.
Let $T_n$ denote the number of satisfying words of length $n$.
Let $S_n$ denote the number of satisfying words of length $n$ that end in either $a$ or $b$.
Let $R_n$ denote the number of satisfying words of length $n$ that end in either $c$ or $d$.
Then, in general, you have that $R_n + S_n = T_n$.
In particular, you have that $R_2, S_2, T_2 = 8, 6, 14,$ respectively.
The challenge is to find the formulas for $R_{n+1}, S_{n+1}, T_{n+1}$ in terms of $R_n, S_n, T_n$.
My approach is to enumerate $R_3, S_3, T_3$, and then use this to derive the necessary formulas.
The $(R_2 = 8)$ two-letter words can be followed either by one of $a,b$ or not.
Therefore, a starter-running-total for the enumeration of $R_3, S_3$ is $R_3 = 2 \times R_2, ~~S_3 = 2 \times R_2$.
The $(S_2 = 6)$ two-letter words can either be followed by $c,d$ or by the $(a,b)$ letter that matches the 2nd letter used.
Therefore, the incremental addition to $R_3, S_3$ generated by extending the $6$ two-letter words is $R_3 = R_3 + (2 \times S_2), ~~ S_3 = S_3 + S_2$
Putting this all together, this implies that:
- $R_3 = (2R_2) + (2S_2) = 2T_2$.
- $S_3 = (2R_2) + S_2 = 2T_2 - S_2.$
- $T_3 = (2T_2) + (2T_2 - S_2) = 4T_2 - S_2$.
The nice thing about the above analysis, is that it is independent of $n$.
So, in general:
- $S_{n+1} = 2T_n - S_n$
- $T_{n+1} = 4T_n - S_n$.
Based on the above formulas, you can immediately generate the following chart:
\begin{array}{| r | r | r |}
\hline
n & S_n & T_n \\
\hline
2 & 6 & 14 \\
\hline
3 & 22 & 50 \\
\hline
4 & 78 & 178 \\
\hline
5 & 278 & 634 \\
\hline
\end{array}
Addendum
A very good case can be made that my answer is incomplete. That is, what is really desired is a closed form expression. Although I was not able to generate such an expression, I can at least demonstrate the attempt that I made.
$S_{n+1} = 2T_n - S_n.$
$T_{n+1} = 4T_n - S_n.$
This leads to
$S_{n+2} = 6T_n - S_n.$
$T_{n+2} = 14T_n - 3S_n.$
This leads to
$S_{n+3} = 22T_n - 5S_n.$
$T_{n+3} = 50T_n - 11S_n.$
Personally, I was not able to find an elegant algebraic expression for $S_{n+k}, T_{n+k}$ in terms of $k$. If I had been able to, I would have then plugged in the values of $S_2, T_2 = 6, 14.$
Let $\alpha=\frac{3+\sqrt{17}}{2}$ and $\beta=\frac{3-\sqrt{17}}{2}$. These are the two roots of $x^2-3x-2$. Then the number of such words of length $n$ is $f(n)=\frac{5}{2\sqrt{17}}\left(\alpha ^n-\beta ^n\right)+\frac{1}{2} \left(\alpha ^n+\beta ^n\right.$
Alternatively, $f(n)$ satisfies $f(n)=3f(n-1)+2f(n-2)$ with $f(1)=4$ and $f(2)=14$.
– pancini Jun 09 '21 at 22:54