# Arranging finite balls of different color such that no balls of the same color are adjacent [duplicate]

The problem involves arranging balls of different color in a line such that no two balls of the same color are adjacent to each other. Eventually I would like to find a generalization of having $m$ different colors of balls and $n$ balls of each color, where each ball besides color are indistinguishable. But for now I will start with $3$ colors, red blue and yellow, and having $3$ of each color.

If we had an infinite number of each ball, then i know the answer would be $3(2^8)$ but this is including arrangements where we might only have red and blue balls alternating and not have any yellows.

One thought was to consider "grouping" the colors in its $3!$ permutations and finding the number of arrangements of the groups. But this wouldn't consider arrangements such as $RYRYBYBRB$

I feel like recurrence may be needed for a generalization but without being able to find this simple case I don't know if I can use it. Searching other questions of this sort doesn't help me either as it isn't this type of restriction.

Brute forcing it is one option but it seems like a mess even for this smaller case, so it would only be good for smaller cases.

Any help would be greatly appreciated

## marked as duplicate by leonbloy, Mike Earnest, Theoretical Economist, Lord Shark the Unknown, BrahadeeshAug 21 '18 at 6:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• Try to state the problem in the question body (not just in the title). The balls are placed in a row or in a circle ? – leonbloy Aug 20 '18 at 22:00
• Oh my I forgot to add that part. These are arranged in a straight line. Will edit – WaveX Aug 20 '18 at 22:01
• This problem covers the cases of $3$ red, $3$ blue, and $3$ green balls arranged in a row so that two consecutive balls are of the same color. – N. F. Taussig Aug 20 '18 at 22:03
• @N.F.Taussig ... "so that no two consecutive balls..." , no? – leonbloy Aug 20 '18 at 22:05
• See this question for possible solutions. I'm certain there are other answers elsewhere on MSE too. – N. Shales Aug 20 '18 at 22:25