Arranging colored balls in a line. 2 balls from 5 distinct colors are collected.


*

*In how many ways can the balls be arranged?

*In how many ways can the balls be arranged so that no two balls of the same color are next to one another?


The first is easy.  If I have 10 spots and 10 balls, then I have 10 choices in the first place, 9 in the second, and so on.  This yields $10!$ ways.
The second is somewhat of a curve ball.  I suppose that the answer would be $10! - N $, where $N$ is the number of arrangements with at least one pair of balls next to one another.  I'm not sure how to approach finding $N$ and would like some help.
Thanks
 A: For the first case, we could arrange the balls in $10!$ different ways if they were unique. However, they aren't unique.  For each color, there are two balls.  Therefore, we can swap any of the balls that are the same color and have the same arrangement, so there are $2!$ different arrangements that are the same for each color. Therefore, we get $\frac{10!}{(2!)^5}$ different ways to arrange the $10$ colored balls. We have the $10!$ for each arrangement and divide by $2!$ $5$ times for the $5$ different colors.

For the second question, this requires the inclusion exclusion principle.  First we must find the number of combinations with one color next to the same colored orb.  To do this, suppose that, say the blue balls, are one unit.  Then there are $\frac{9!}{(2!)^4}$ arrangements where the blue balls are next to each other.  We continue pairing colors that will become a unit like this and then apply the inclusion exclusion principle to see that the number of arrangements where no two similarly colored balls are next to each other is given by the following equation:
$\frac{10!}{(2!)^5}-{5\choose1}\frac{9!}{(2!)^4}+{5\choose2}\frac{8!}{(2!)^3}-{5\choose3}\frac{7!}{(2!)^2}+{5\choose4}\frac{6!}{(2!)^1}-{5\choose5}\frac{5!}{(2!)^0}=39,480$
I only very briefly explained the use of the Inclusion-Exclusion Principle, but you can find more at its wikipedia page 
A: Consider a smaller case, two balls of two colours Red and Blue, we'll denote a red ball with $r$ and a blue ball with $b$. The options are $rrbb, rbrb, rbbr$ and then the same again with $r$ and $b$ flipped round. That means there are 6 ways. You are right, there are 4! ways to arrange the balls, but we have to account for how we could swap the blue balls, and how we could swap the red balls; if we interchange two blue balls, we still have the same arrangement. How many ways are there to arrange each set of coloured balls?
For the second question, if we only have four balls then we have 4 choices for the first ball, but if this is red we have to have a blue ball next (so two choices), this then forces the third ball to be red (so one choice) and the final ball has to be blue (no choice). So we have $4*2*1$ ways to arrange them, and again we account for the fact that we could arrange the blue balls in two ways, and the red balls in two ways, giving us only 2 options - $rbrb, brbr$. With this logic, I believe that the answer to the second part is 12,600 but the formula is for you to work out (I'm not 100% sure of this, the complication is that you have a defined start point, this would be simpler if the colour balls were in a loop).
A: This has a nice pattern, but Jair Taylor has shown a formula that can tackle any such case.
Define polynomials for $k\geq 1$ by  $q_k(x) =
\sum_{i=1}^k \frac{(-1)^{i-k}}{i!} {k-1 \choose i-1}x^i$.
e.g. for $k=2, q_2(x)$ works out to ${(x^2-2x)}/2!$
The number of permutations will be given by

$$\int_0^\infty \prod_j q_{k_j}(x)\,  e^{-x}\,dx.$$

The specific formula for this problem can be seen at Wolframalpha yielding the answer as $39,480$
