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

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$
