There are 12 red balls, 15 white balls and 17 black balls in a box. A person extracts all the balls, one at a time.

What’s the probability that all the red balls will be extracted before the white balls and that all the white balls will be extracted before the black balls?

There are two ways to do it, one is more complicated, the other quite simple.

Let’s start with the complicated one. Let’s calculate all the sequences fulfilling the condition and divide by the number of total sequences.

Obviously, the last ball must be black. Then, let’s fix the 12 red balls. There are 13 spots where the 15 white balls can stay, so the problem is equivalent to: in how many ways can we write 15 as a sum of 13 non negative factors, with the limitation that the last must be positive (there must be at least one white ball after the red ones). Also, it’s equivalent to writing 14 as a sum of 13 non negative factors. This is a very notorious problem (knives and balls), and the result is:

Now, apart from the last ball, 27 balls are fixed, hence there are 28 places where the remaining 16 black balls can stay. Hence, the problem is equivalent to writing 16 as a sum of 28 non-negative numbers, the same as before. The solution is:

Hence, the final result is:

Now, the simple solution is this: one black ball must occupy the last place and this happens with probability:

Also, considering the sequence of the red and white balls, a white ball must occupy the last place, and this happens with probability:

By multiplying these two results, we get the final probability: