TITLE: Number of possible permutations of n1 1's, n2 2's, n3 3's, n4 4's such that no two adjacent elements are same?
QUESTION [6 upvotes]: Given $n_1 $ number of  $1 $'s,  $n_2 $ number of  $2 $'s,  $n_3 $ number of  $3 $'s,  $n_4 $ number of  $4 $'s.
form a sequence using all these numbers such that two adjacent numbers should not be same.
I have tries lot of things but nothing worked.
can somebody tell me how to solve this problem?

REPLY [2 votes]: Here is  a variation based upon generating functions of Smirnov words. These are words with no equal consecutive characters. (See example III.24 Smirnov words from Analytic Combinatorics by Philippe Flajolet and Robert Sedgewick for more information.) 

We encode the digits 
  \begin{align*}
1,2,3,4 \qquad\text{as}\qquad d_1,d_2,d_3,d_4
\end{align*}
  and look  for Smirnov words of length $n_1+n_2+n_3+n_4$ built from $d_i,1\leq i\leq 4$ with each letter occurring exactly $n_i\geq 1$ times.

A generating function for the number of Smirnov words over a four letter alphabet $V=\{d_1,d_2,d_3,d_4\}$ is given by
\begin{align*}
\left(1-\frac{4z}{1+z}\right)^{-1}
\end{align*}
We  use      the coefficient of  operator  $[z^n]$     to  denote the coefficient of $z^n$ in a series $A(z)$. The number of all Smirnov words of length $n_1+n_2+n_3+n_4$ over a four letter alphabet is therefore 
\begin{align*}
\left[z^{n_1+n_2+n_3+n_4}\right]\left(1-\frac{4z}{1+z}\right)^{-1}
\end{align*}

Since we want to count the number of words of length $n_1+n_2+n_3+n_4$ with each character in $d_i$ occurring $n_i$ times, we keep track of each character. We obtain the number of wanted words as
  \begin{align*}
\color{blue}{\left[d_1^{n_1}d_2^{n_2}d_3^{n_3}d_4^{n_4}\right]\left(1-\frac{d_1}{1+d_1}-\frac{d_2}{1+d_2}-\frac{d_3}{1+d_3}-\frac{d_4}{1+d_4}\right)^{-1}}
\end{align*}

Example:
We consider the example of @N.Shales setting $(n_1,n_2,n_3,n_4)=(4,3,3,2)$ and we obtain in accordance with his result (and with some help of Wolfram Alpha)
\begin{align*}
\left[d_1^4d_2^3d_3^3d_4^2\right]\left(1-\frac{d_1}{1+d_1}-\frac{d_2}{1+d_2}-\frac{d_3}{1+d_3}-\frac{d_4}{1+d_4}\right)^{-1}\color{blue}{=23\,254}
\end{align*}