Cody has 4 types of onions:
If Cody has 23 onions, how many different distributions of colors can there be?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
@Aditya Raut I think there was a tiny bit of sarcasm in 'use the formulas of Polynomial expansions', wasn't there? :P - Saying this because you would have to find the coefficient of x 2 3 in the Taylor expansion of ( ( 1 − x ) ( 1 − x 2 ) ( 1 − x 3 ) ( 1 − x 5 ) ) − 1 , which is, I think, humanly impossible to do..
Log in to reply
I agree, but it's not impossible. It's "DIfficult" . But if you use right formula that is a worth 4 minutes thing.
Log in to reply
What do you mean by the right formula? Can you write out your process in obtaining 127 as the coefficient? I have reached the step where I have the generating functions as a product of 4 polynominals. If I expand by hand, it would be the same as counting the individual cases that satisfy a + b + c + d = 23 under the given conditions. Thanks!
It's actually humanly impossible..as this would be the same thing as finding answers by hit and trial.
Had reached that equation of generating function but didn't know how to find the co-efficient. Can you give its detailed version(rather than wolfram version)?
Log in to reply
Lol, it took me 10min to calculate ((1-x)(1-x^2))^-1 and i got (sum from 0 to inf of:0,25 (2n+(-1)^(n+2) x^n.Further it's too hurd to calculate.I think there must be a simple way to calculate this monster,but i don't understand why nobody could do this.
Mathematica Code:
1 2 3 |
|
How do we solve it by hand only?
I've never heard of generating functions!
Log in to reply
Yeah, you have never heard of it because you always "typed of it" , and "used it" ..... So you got no time to hear it :( @Cody Johnson
Log in to reply
I read this topic under the name of multinomial theorem in my schools....I didn't know that this is called generating functions..... Thnx for your useful info. By the way , are you preparing for JEE 2015 ?? and 1 more thing , I had used this method of 'finding the coefficient' but never understood the logic behind it.. can u please explain it to me ?
Log in to reply
@Vighnesh Raut – Read the brilliant wiki on generating functions, it will help a lot. Or better yet, watch some YouTube videos.
The dynamic programming approach is slower (and bigger) than the computation given through generating functions.
1 − x a 1 = 1 + x a + x 2 a + ⋯ is equivalent to using multiples-of- a type onions. So the number of ways we can make n using Purple, Green, Red, and Blue is given by the n th coefficient of
1 − x 1 ⋅ 1 − x 2 1 ⋅ 1 − x 3 1 ⋅ 1 − x 5 1 = n = 0 ∑ ∞ a n x n and given that ( 1 − x ) ( 1 − x 2 ) ( 1 − x 3 ) ( 1 − x 5 ) = 1 − x − x 2 + x 4 + x 7 − x 9 − x 1 0 + x 1 1 , we obtain 1 = ( 1 − x − x 2 + x 4 + x 7 − x 9 − x 1 0 + x 1 1 ) n = 0 ∑ ∞ a n x n . = n = 0 ∑ ∞ a n x n − n = 1 ∑ ∞ a n − 1 x n − n = 2 ∑ ∞ a n − 2 x n + n = 4 ∑ ∞ a n − 4 x n + n = 7 ∑ ∞ a n − 7 x n − n = 9 ∑ ∞ a n − 9 x n − n = 1 0 ∑ ∞ a n − 1 0 x n + n = 1 1 ∑ ∞ a n − 1 1 x n
If we define a n = 0 for all n < 0 , then we may rewrite this as 1 = n = 0 ∑ ∞ ( a n − a n − 1 − a n − 2 + a n − 4 + a n − 7 − a n − 9 − a n − 1 0 + a n − 1 1 ) x n
By equating coefficients then we obtain the recurrence relation that for n > 0 , a − n = 0 , a 0 = 1 and
a n = a n − 1 + a n − 2 − a n − 4 − a n − 7 + a n − 9 + a n − 1 0 − a n − 1 1
This is easy enough to compute to a 2 7 by hand. But for those of us too lazy for such tasks, a simple C implementation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
count = 0
for blue in xrange(0,24,5):
for red in xrange(0,24,3):
for green in xrange(0,24,2):
for purple in xrange(24):
if purple+green+red+blue == 23:
count=count+1
print count
Very good, I appreciate everyone who can program! I also would have used the same method if I wasn't the person who posted this problem :P A good way of
Another way is to do casework on d (which isn't as bad as it sounds since there are only 5 cases).
Case 1: d=20.
We see that (0, 0, 3, 20) works.
(1, 2, 0, 20) and (3, 0, 0, 20) works as well.
We have 3 for this case.
Case 2: d=15 For simplicity, I'm going to leave d=15 out of the quadruple.
(0, 2, 6) and (2, 0, 6) 2 in this subcase where c=6.
(1, 4, 3), (3, 2, 3), (5, 0, 3) 3 in this subcase.
(0, 8, 0) .. (8, 0, 0) 5 in this subcase.
Total in this case is 10.
Case 3: d=10
c=12. 1 here
c=9. 3 here
c=6. 4 here
c=3. 6 here
c=0. 7 here
At this point, you should see the pattern (skip 1, skip 2). We can prove this by taking two cases (one where c is odd and where c is even).
There are 21 total here.
Case 4: d=5
c=18. 1 here
c=15. 2 here
From here on, we can just get that the total for this case is 1+2+4+5+7+8+10=37 (using our pattern).
Case 5: d=0
c=21. 2 here
c=18. 3 here
2+3+5+6+8+9+11+12=56 in this case.
Summing it all up, we get 3 + 1 0 + 2 1 + 3 7 + 5 6 = 1 2 7
Very bashy but can be done all on paper.
It is good answer but during examination there may be a chance of missing any possibility
As with almost everyone else it seems, I've solved this via generating functions and then done some computer magic to extract the required coefficient. But I thought generating functions were meant to make things easier? In the absence of technology, the calculation required to find the coefficient of x 2 3 seems to me to be exactly as hard as finding the number of solutions to the original problem...
Easy and fast O(n^2) solution implementing generating functions in python with sympy:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Used Taylor series expansion at x=0 of (1/{(1-x)(1-x^2)(1-x^3)(1-x^5)} and found the coefficient of x^23, using WolframAlpha, giving answer=127.
Problem Loading...
Note Loading...
Set Loading...
We can use generating functions!
We want to find the number of non-negative integer solutions to a + b + c + d = 2 3 a = k where 0 ≤ k ≤ 2 3 ,
b = 2 k where 0 ≤ k ≤ 1 1 ,
c = 3 k where 0 ≤ k ≤ 7 and
d = 5 k where 0 ≤ k ≤ 4 . (No one can exceed 23)
So the generating function will be ( k = 0 ∑ 2 3 x k ) ( k = 0 ∑ 1 1 x 2 k ) ( k = 0 ∑ 7 x 3 k ) ( k = 0 ∑ 4 x 5 k )
In this, use the formulas of Polynomial expansions or easier way, use Wolfram input
And you see that the co-efficient of x 2 3 in the expansion is 1 2 7 .