This is similar to this question, and I wanted to apply the technique of inclusion-exclusion to see if I understand it. I try to explain as many details as possible in my reasoning, and I would like to know if my solution is correct?
In an alphabet of $n$ distinct letters, how many words of length $3n$, where each letter appears $3$ times, can be formed such that no $3$ consecutive letters are the same?
Attempt.
Suppose first that the identical letters are distinguishable. Choose $k$ letters to form consecutive triples in our word, where $k=0,1,...,n$. There are ${n \choose k}$ choices for these letters. Then, we may order the remaining letters arbitrarily, of which there are $(3n-k)!$ ways to do so, since these are just permutations. Implicitly, we are regarding each triple as one letter.
Next, since we assumed the identical letters are distinguishable, each triple has $3!=6$ different orderings, giving a total of $6^k$ different orderings for our $k$ triples, by the product rule. These three steps are independent, so by the product rule, we get there are ${n \choose k}(3n-k)!6^k$ words with $k$ consecutive triples.
However, we now must account for the fact that there are identical letters. Each triple has $3!=6$ different orderings, so we have to divide by $6^n$ to remove the duplicate words. Thus, by principle of inclusion-exclusion, the total number of words is $$\sum_{k=0}^n \frac{1}{6^n} (-1)^k{n\choose k} (3n-k)!6^k = \frac{1}{6^n} \sum_{k=0}^n (-1)^k {n \choose k}(3n-k)!6^k.$$
Your proposed formula returns $-1$ when $n=1$ so cannot be correct.
You have the right idea, but when you remove $k$ occurrences of consecutive triples, there are $3n-3k$ letters remaining to permute.
To use your approach of treating each consecutive triple as a single letter, when you consider $k$ occurrences of consecutive triples, there are $3n-2k$ letters to permute because you lose $2$ letters for each triple.