Artificial intelligent assistant

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.

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$$

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 84dd9c57120d715c0e33dd41e8c2bd9e