TITLE: Arrangements of a,a,a,b,b,b,c,c,c in which no three consecutive letters are the same
QUESTION [16 upvotes]: Q: How many arrangements of a,a,a,b,b,b,c,c,c are there such that
$\hspace{5mm}$ (i). no three consecutive letters are the same?
$\hspace{5mm}$ (ii). no two consecutive letters are the same?
A:(i). 1314. ${\hspace{5mm}}$ (ii). 174.
I thought of using the General Principle of Inclusion and Exclusion along with letting $p_i$ denote a property that.. , and doing so, I will evaluate $E(0)$, which gives us the number of arrangements without any of the properties. 
How do I go about doing that? I am trying to use the method stated above in solving this question, but I am unable to generalize the properties $p_i$.

REPLY [11 votes]: This answer is based upon a generating function of generalized Laguerre polynomials
\begin{align*}
  L_k^{(\alpha)}(t)=\sum_{i=0}^k(-1)^k\binom{k+\alpha}{k-i}\frac{t^i}{i!}
  \end{align*}
The Laguerre polynomials have some remarkable combinatorial properties and one of them is precisely suited to answer problems of this kind. This is nicely presented in Counting words with Laguerre series by Jair Taylor. We find in section $3$ of this paper:

Theorem: If $m_1,\ldots,m_k,n_1,\ldots,n_k$ are non-negative integers, and $p_{m,n}(t)$ are polynomials defined by
  \begin{align*}
  \sum_{n=0}^\infty p_{m,n}(t)x^n=\exp\left(\frac{t\left(x-x^m\right)}{1-x^m}\right)
  \end{align*}
  then the total number of $k$-ary words that use the letter $i$ exactly $n_i$ times and do not contain the subwords $i^{m_i}$ is
  \begin{align*}
  \int_0^\infty e^{-t}\prod_{j=1}^k p_{m_j,n_j}(t)\,dt
  \end{align*}

Here we consider a $3$-ary alphabet $\{a,b,c\}$ and words built from the characters  $$a,a,a,b,b,b,c,c,c$$

First case: Bad words $\{aaa,bbb,ccc\}$
We have $m_1=m_2=m_3=3, n_1=n_2=n_3=3$
We obtain with some help of Wolfram Alpha
\begin{align*}
p_{3,3}(t)&=[x^3]\exp\left(\frac{t\left(x-x^3\right)}{1-x^3}\right)\\
&=[x^3]\left(1+tx+\frac{1}{2}t^2x^2+\left(\frac{1}{6}t^3-t\right)x^3+\cdots\right)\\
  &=\frac{1}{6}t^3-t
\end{align*}

It follows
\begin{align*}
\int_0^\infty e^{-t}\left(\frac{1}{6}t^3-t\right)^3\,dt=1314
\end{align*}

Second case: Bad words $\{aa,bb,cc\}$
We have $m_1=m_2=m_3=2, n_1=n_2=n_3=3$ and obtain
\begin{align*}
p_{2,3}(t)&=[x^3]\exp\left(\frac{t\left(x-x^2\right)}{1-x^2}\right)\\
 &=[x^3]\left(1+tx+\left(\frac{1}{2}t^2-t\right)x^2+\left(\frac{1}{6}t^3-t^2+t\right)x^3+\cdots\right)\\
  &=\frac{1}{6}t^3-t^2+t
\end{align*}

It follows
\begin{align*}
\int_0^\infty e^{-t}\left(\frac{1}{6}t^3-t^2+t\right)^3\, dt=174
\end{align*}