Use the inclusion-exclusion principle to determine Use the inclusion-exclusion principle to determine :
(a) the number of ways there are to choose nineteen balls (identical apart from their colour) from a pile of red, blue, yellow and green balls if there have to be at most seven balls of each colour?
(b) the number of arrangements of length 9 of the numbers 1, 2, 3 and 4 (repetitions allowed) in which each number occurs at least once.
I have no idea how to approach part (a). For part (b), I think that the sets, say Ai, should be set up to be arrangements that do not have 1 or 2 or 3 or 4. Example : A1 be the set of length 9 of the numbers 2,3,4 and A2 be the set of length 9 of the numbers 1,3,4 and so on. Would this be correct and, if it is, how would I proceed with it?

$a)$
How many ways are there to select them so that two colors have more than $7$ balls? There are $\binom{4}{2}=6$ ways to choose the two colors. After that we can go ahead and take out $8$ balls of each of those colors. We must now select $19-16=3$ balls out of $4$ colors. By stars and bars there are $\binom{6}{3}=20$ ways to do this. So $6\cdot20=120$ ways in total.
How many ways are there to select them so that exactly one color has more than $7$ balls? First select the color in $4$ ways,let us assume it is red. After this take out $8$ balls of that color. We must now select $19-8=11$ balls out of $4$ colors, by stars and bars there are $\binom{14}{3}=364$ ways to do so. However out of those $364$ ways there are $20$ ways in which red and blue appear more than seven times, $20$ ways in which red and green appear more than $7$ times and $20$ ways in which red and yellow appear more than $7$ times. Therefore there are $364-3\cdot20=304$ ways in which only red is repeated. Therefore there are $4\cdot304=1216$  colorings in which exactly one color appears more than seven times.
Once we have this we can count the number of colorings in which no color apears more than $7$ times. This is because if we are allowed to color freely then by stars and bars there are $\binom{22}{3}=1540$ colorings. Therefore there are $1540-120-1216=204$ coloring in which no color appears more than $7$ times.
$b)$
This one is easier, we solve for an arbitrary length $n$ of words, where $n\geq 4$:
There are $1+1+1+1$ sequences with exactly one number.
How many sequences have exactly $2$ numbers? there are $6$ ways to choose the numbers and then $2^{n}-2$ sequences, so $6(2^n-2)$ total.
How many sequences have exactly $3$ numbers? There are $4$ ways to choose them. After this there are $3^n$ sequences with those $3$ numbers, out of these $3$ use exactly $1$ number and $3(2^n-2)$ use exactly $2$ numbers. Hence $3^n-3\cdot2^n-3$ use all of those three numbers. So $4(3^n-3\cdot2^n+3)$ total.
Therefore there are $4^n-4-6(2^n-2)-4(3^n-3\cdot2^n+3)$ words that use all four numbers.
