Expected Value: Animal Cages The Happy Animals Kennel has $18$ cages in a row. They allocate these cages at random to $6$ dogs, $6$ cats, and $6$ pot-bellied pigs (with one animal per cage). All arrangements are equally likely.
Let $A$ be the number of times in the row of cages that two animals of the same species are adjacent. For example, in the arrangement DCPCDPPPDCDPCDCCPD (where D=dog, C=cat, and P=pig), we have $A=3$.
What is the expected value of $A$?
UPDATE: Oops, I forgot to include what I've got so far!  It would be almost impossible to list all of the possibilities and expected value is a new topic for me, so I'm fuzzy on the topic.
 A: We use the Linearity of Expectations.  For $i\in \{1,\cdots,17\}$ let $X_i$ be the indicator variable telling you whether Cage $i$ contains the same animal as Cage $i+1$ (thus $X_i=1$ if the two animals match, and $0$ otherwise).  Then $E[X_i]=\frac 5{17}$ and the answer you want is $$E=E\left[\sum X_i\right]=\sum E[X_i]=17\times \frac 5{17}=5$$
A: Suppose we have  three types of animals, $A,B$  and $C.$ Construct the
generating function of strings over this alphabet classified according
to the last letter with adjacent equal letters marked. We get
$$F_A(z) - a = va F_A(z) + a F_B(z) + a F_C(z)$$
and
$$F_B(z) - b = b F_A(z) + vb F_B(z) + b F_C(z)$$
and finally
$$F_C(z) - c = c F_A(z) + c F_B(z) + vc F_C(z).$$
We are interested in 
$$Q_{A,B,C} (z) =
\left.\frac{\partial}{\partial v} F_{A,B,C}(z)\right|_{v=1}.$$
We get
$$Q_A(z) = \left.aF_A(z)\right|_{v=1} + aQ_A(z)
+ a Q_B(z) + a Q_C(z).$$
and two more that are cyclic iterates. We require
$$P(z) = Q_A(z) + Q_B(z) + Q_C(z)$$
which yields by adding the cyclic iterates
$$P(z) = \frac{a^2+b^2+c^2}{1-a-b-c} + (a+b+c) P(z)$$
or
$$P(z) = \frac{a^2+b^2+c^2}{(1-a-b-c)^2}.$$
To extract the coefficient on this restrict to the number 
of animals of each type being equal say $M$ to get
$$\left([a^{M-2} b^M c^M] +
[a^M b^{M-2} c^M] +
[a^M b^M c^{M-2}] \right) 
\sum_{q=0}^\infty (q+1) (a+b+c)^q
\\ = 3\times (3M-1) \times {3M-2\choose M, M, M-2}.$$
With $M=6$  i.e. six animals of  each type the  expectation thus works
out to
$$\bbox[5px,border:2px solid #00A000]{
{18\choose 6,6,6}^{-1}
\times 3 \times 17 \times {16\choose 6,6,4}
= 5.}$$
The generic formula is
$${3M\choose M,M,M}^{-1} \times 3\times (3M-1)\times
{3M-2\choose M,M,M-2}
\\ = \frac{1}{3M} \times 3 \times M (M-1)$$
or
$$\bbox[5px,border:2px solid #00A000]{
M-1.}$$
Remark. Observe that we did not  in fact need to solve any systems
of equations.
