TITLE: 12-letter words with four X's, four Y's, and four Z's
QUESTION [5 upvotes]: Okay, per the title, we're constructing 12-letter words with four X's, four Y's, and four Z's. How many such words have no X's in the first 4 letters and no Y's in the next 4 letters?
Let me show my work with what I got. Let's do casework based on the number of X's in the last 4 letters.
YYYY ZZZZ XXXX: 1 possibility
YYYZ ZZZX XXXY: 4(4)(4) = 64 possibilities
YYYY ZZZX XXXZ: 4(4) = 16 possibilities
YYYZ XXZZ XXYZ: 4(6)(12) = 288 possibilities
YYZZ XXZZ XXYY: 6(6)(6) = 216 possibilities
YYYY XXZZ XXZZ: 6(6) = 216 possibilities
YYYY XXXZ XZZZ: 4(4) = 16 possibilities
ZZZY XXXZ XYYY: 4(4)(4) = 64 possibilities
YYZZ XXXZ XZYY: 6(4)(12) = 288 possibilities
YYYZ XXXZ XYZZ: 4(4)(12) = 192 possibilities
ZZZZ XXXX YYYY: 1 possibility
YYYY XXXX ZZZZ: 1 possibility
Adding up, we have 1363 possibilities.
(1) Is this correct?
(2) That was a pain to do all the casework. Is there a cleaner way to solve this problem?

REPLY [4 votes]: When there are $k$ X's in the last $4$ positions (and therefore $4-k$ X's in the middle $4$ positions) there are $\binom 4k \binom 4{4-k} = \binom 4k^2$ ways to choose the position of the X's. After that, the Y's have $8-k$ places to go which are not in the middle and not occupied by X's; there are $\binom{8-k}{4}$ ways to choose their positions. Finally, the Z's go in the last $4$ spaces.
This gives us a sum of
$$
   \binom 40^2 \binom 84 + \binom 41^2 \binom 74 + \binom 42^2 \binom 64 + \binom 43^2 \binom 54 + \binom 44^2 \binom 44
$$
which simplifies to
$$
    1^2 \cdot 70 + 4^2 \cdot 35 + 6^2 \cdot 15 + 4^2 \cdot 5 + 1^2 \cdot 1
$$
or $70 + 560 + 540 + 80 + 1 = 1251$.
In general (when there are $n$ X's, $n$ Y's, and $n$ Z's, with no X's in the first $n$ letters and no Y's in the middle $n$ letters) the number of words is given by the $n^{\text{th}}$ Apéry number: sequence A005258 in the OEIS. There is no better closed form known than a generalization of the sum above, unless you allow hypergeometric functions.