A candy factory has an endless supply of red, orange, yellow, green, blue, black, white, and violet jelly beans. The factory packages the jelly beans into jars in such a way that each jar has 200 beans, equal number of red and orange beans, equal number of yellow and green beans, one more black bean than the number blue beans, and three more violet beans than the number of white beans. One possible color distribution, for example, is a jar of 50 yellow, 50 green, one black, 48 white, and 51 violet jelly beans. As a marketing gimmick, the factory guarantees that no two jars have the same color distribution. What is the maximum number of jars the factory can produce? Although the answer can be found in the link below, I did not really understand it, if someone can give more details on the derivation.


  • 1
    $\begingroup$ What specifically is it you don't understand? $\endgroup$
    – saulspatz
    Jul 20, 2019 at 13:47

1 Answer 1


I will try to put it in a more understandable way.

Let $r$, $g$, $b$ and $w$ denote the number of red, green, blue and white beans, respectively. Then the number of orange, yellow, black and violet beans are $r$, $g$, $b+1$, and $w+3$ respectively.

Since total number of beans are 200, we must have $$ 2r + 2g + 2b + 2w + 4 = 200 $$ $$ \implies r + g + b + w = 98 $$

where $r,g,b,w \geq 0$. All remains is to find the number of non-negative integer solutions of the above equation.

Now, consider a bit-string of length 101 (= 98+3). We choose 3 positions in this string where we will put 0s, and rest will be 1s. These zeroes act like a separator. It partitions the string in four blocks of consecutive 1s. The number of 1s in each block represents the values of variable $r$, $g$, $b$, $w$ from left to right. And, the number of such partitions will give us the number of solutions of the equation.

For example, consider the equation $x_1 + x_2 + x_3 + x_4 = 8$, where $x_i \geq 0$. Here, the bit-string 11011101011 corresponds to the solution $(2,3,1,2)$. And, the bit-string 01111001111 corresponds to the solutions $(0,4,0,4)$.

Now back to our problem, the number of ways of partitioning is same as selecting three distinct positions in the string. Hence, our answer is $\binom{101}{3}$.

  • $\begingroup$ thank you very much, with the example this is much more clear to me $\endgroup$
    – AAC
    Jul 20, 2019 at 14:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .