[Math] 10 Balls in a row (4B 4W 2R), with not all balls of any color consecutive

combinatorics

Let N be the number of ways to arrange four black balls, four white balls, and two red balls in a row, so that for each color, not all the balls of that color are consecutive. (For example, if B, W, and R represent a black, white, and red ball, respectively, then the arrangement WRWWRBBBBW is not allowed, because all the black balls are consecutive.) Find the remainder when N is divided by 1000. Many cases blew my head off.(first all black, then white, then red, then two together-3 cases and then all three together…)

Best Answer

We will compute the answer by inclusion exclusion.

The total number of ways to arrange the 10 balls is given by $\frac {10!}{4! 4! 2!} = 3150$. These include arrangements that violate the conditions so we need to remove them.

We first remove the cases where all black are consecutive. To count the number of such arrangements imagine merging all black balls into one segment, so in total we have $\frac {7!}{1! 4! 2!} = 105$ ways of arranging the 4 white balls, the 2 red balls and the black segment. Similarly, work for the case where all white balls or red are consecutive and subtract $105$ and $630$ respectively.

By subtracting the above we double-counted the cases where balls of two or more colors are consecutive at the same time and we need to add them back. First, we need to include back the cases where both the white balls and the black balls are consecutive. These are in total $\frac {4!}{1! 1! 2!} = 12$ cases. We do the same for black and red, and white and red to add $\frac {6!}{4! 1! 1!} = 30$ and $\frac {6!}{ 1! 4! 1!} = 30$ cases respectively.

Finally, we need to subtract the number of ways to arrange balls of all colors consecutively which is exactly $\frac {3!}{ 1! 1! 1!} = 6$ ways. So in total we have $3150 - 105 - 105 - 630 + 12 + 30 + 30 - 6 = 2376 \equiv376\pmod{1000}$

Related Question