Candy Factoryal
This is classic. It's also basic but important in combinatorial math.
A restatement: There are k colors/types of jelly beans and each jar contains exactly n jelly beans. How many different jars can be produced (or are there)?
Solution:
Let x(i) denote the number of jelly beans of type i in the jar where i belongs to the set {1,2,...,k}. Clearly x(i) belongs to the set {0,1,2,...,n}. In each jar we have:
x(1)+x(2)+...+x(k)=n. (**1**)
So, we are after the number of solutions to (**1**).
There are couple of ways one can approach the problem. One is doing recursion. The second is a more direct combinatorial approach.
I will leave the frist approach to others and will focus on the second approach here:
Take any jar and pour out its contents onto a table and group like jelly beans together ALL on a straight line. For example, for k=4 and n=9, here are some arrangements of jelly beans:
Below you will see smiley faces separated by |. Going from left to right, the first few faces before the first | represent the first type of jelly beans in the jar. Continuing to the right, the group of faces to the right of the first | but to the left of the second | represents the second type of jelly beans. An so on.
(1) 4
|
|
| 3
(2) 6
| | 2
|
(3)
|
|
| 6
(4) | |
| 8
(5) 4
| | | 5
(6) 4
| 5
| |
(7) 9
| | |
The first line says there are 4 jelly beans of type 1, 1 of type 2, 1 of type 3, 3 of type 4.
The second line says there are 6 jelly beans of type 1, 0 of type 2, 2 of type 3, and 1 of type 4.
The fourth line says there are 0 of type 1, 0 of type 2, 1 of type 3, 8 of type 4.
The fifth line says there are 4 of type 1, 0 of type 2, 0 of type 3, 5 of type 4.
The sixth line says there are 4 of type 1, 5 of type 2, 0 of type 3, 0 of type 4.
The seventh line says there are 9 of type 1, 0 of type 2, 0 of type 3, 0 of type 4.
As we look at the seven cases above we make an unavoidable observation: In each line we have two kinds of symbol: smiley face and a bar |. There are 9 smiley faces and 3 bars |. Every lline is a linear arrangement of 9 faces with three bars. So, we have 9+3=12 things, of which 3 are bars and the rest faces. In how many ways can this be done? Obviously, C(12,3); i.e., 12 choose 3.
Now, in the general case, we have k variables x(i), which are separated in the equation by (k-1) plus signs (+). Each plus sign (+), like the bar |, is a separator. So, we have n beans to be separated into their respective groups by (k-1) bars. So, we have a total of n+(k-1) things of which (k-1) are bars |, and the rest are faces. So, the answer is
C(n+k-1, k-1).
So, for n=100, k=6, we have the answer as: C(105, 5).