Here is the question;

If there is an unlimited number (or at least 24 of each color) of red, green, white, and black jelly beans, in how many ways can Douglas select 24 of these candies so that he has an even number of white beans and at least six black ones?

This problem is solved using generating functions in my textbook (I am learning this for tje first time). I tried to understand it. But wasn't able to get it clearly. Here are the steps mentioned in book:

The polynomials associated with the jelly bean colors are as follows:

Red (green): $$1 + x + x^2 + .... + x^{24}$$ White: $$1 + x^2 + x^4 +.... +x^{24}$$ Black: $$x^6+x^7 + ... x^{24}$$

So the answer to the problem is the coefficient of $x^{24}$ in the generating function $$f(x) = (1 + x + x^2 + ... + x^{24})^2 (1 + x^2 + x^4 +...+x^{24})(x^6 + x^7+ ... + x^{24})$$

I am not worried about the answer. My problem is about writing these polynomials. What is the idea behind taking series for red and green upto $x^{24}$? Since 6 black beans are in every selection why isn't it just upto $x^{18}$? (Which is 24 -6)

My teacher told me it is because collection of beans is infinity. But I didn't get it. Even if the collection is infinity, the selection is limited to 24 with atleast 6 black beans and even number of white beans. This is my simple 'stupid' logic. I can't get rid of that logic. I need some conceptual clarity. Can you help me?

Question ref: Discret and Combinatorial Mathematics by Ralph Grimaldy 5 th edn example 9.2

  • 1
    $\begingroup$ Your approach is correct, but so is the one in the book, because the $x^{24}$ terms won't figure in the answer, for precisely the reason you state. All we're interested in is the coefficient of $x^{24}$ in the product, and both approaches give the same answer. $\endgroup$
    – saulspatz
    Feb 3, 2021 at 19:29

1 Answer 1


You'll get the same answer either way (or even if you make each factor an infinite sum). Note that every term in the result will include a contribution of $x^6$ or larger from the last factor, so the $x^{19}$ and higher terms in the other factors will only contribute to $x^{25}$ and higher terms of the result - they won't affect the $x^{24}$ coefficient.


You must log in to answer this question.

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