Looking for recursive formula to the number of words length $n$ with the letters $A,B,C $and the following restrictions: neither $AB$ nor $CA$ can occur as a string in the word.
I tried to build a legal word from the start and tried to look at the last letter of a word of length $n-1.$ The problem is, there is a difference between the number of options for letters to follow $A,C$ than the number of options for letters to follow $B$.
Let $a_n$ be the number of legal strings of length $n$ that end in $A$, $b_n$ the number that end in $B$, and $c_n$ the number that end in $C$. Let $d_n=a_n+b_n+c_n$; $d_n$ is the total number of legal strings of length $n$. Then
$$\begin{align*} &a_n=a_{n-1}+b_{n-1}\;,\\ &b_n=b_{n-1}+c_{n-1}\;,\text{ and}\\ &c_n=a_{n-1}+b_{n-1}+c_{n-1}\;. \end{align*}$$
Thus, $c_n=d_{n-1}$, so we can rewrite the system as
$$\begin{align*} &a_n=a_{n-1}+b_{n-1}=d_{n-1}-c_{n-1}=d_{n-1}-d_{n-2}\;,\\ &b_n=b_{n-1}+c_{n-1}=d_{n-1}-a_{n-1}=d_{n-1}-d_{n-2}+d_{n-3}\;,\text{ and}\\ &c_n=a_{n-1}+b_{n-1}+c_{n-1}=d_{n-1}\;, \end{align*}$$
so that
$$d_n=a_n+b_n+c_n=3d_{n-1}-2d_{n-2}+d_{n-3}\;.$$
This sequence is OEIS A$034943$; there does not appear to be a nice closed form, though since the characteristic polynomial is only a cubic, in principle one can solve it and write down a closed form in terms of the roots.