Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 20 Online
OpenStudy (anonymous):

I'm on ps2 problem 1 and 2. I wrote some code that prompts the user to enter a range and finds the first combination of 6,9, and 20 packs that will that adds up to that. I've found that you get at least one combination from 43 on, but I don't really understand the math behind it, specifically what the theorem is asking for. Basically i understand it in practice, but not in theory. Below is a link to the code i've come up with http://codepad.org/ooVDsOzJ

OpenStudy (anonymous):

I found the best way to understand the math is work the problem out on paper. By combining possible solutions by hand the math will reveal itself. I made a chart with three columns and just started showing how putting 6pc 9pc 20pc in different amounts would come up with a given number and how smaller values would be impossible to reach as in 1,2,3,4,5,7,8pc and how large numbers would always be possible. You will see very quickly that after 43 every number higher is possible using combinations of lesser values. Chart it out and it becomes very clear what is going on. with 6x+9y+20z=n

OpenStudy (anonymous):

Will do, thank you for your response.

OpenStudy (maitre_kaio):

That one could be in the FAQ (if there was one :P ). Here's my answer, sorry for those who have already read it in previous questions: Basically, it is just a proof by recursion. I would explain it this way in english: Say I want to buy an arbitrary number x of nuggets and i know that it is possible to buy x, x+1,..., x+5 nuggets. I can always buy c boxes of 20 (c >=0) plus n others (0 < n < 20). Now I just need to demonstrate that can I buy n nuggets I can buy x + 6, x + 11 just by adding a box of 6. I can buy x + 12, ... x + 14 by adding a box of 9. I can buy x + 15, ..., x + 19 by adding a box of 6 and a box of 9. I can buy x + 20 by adding a box of 20. For any number greater than x + 20, I can buy a number of boxes containing 20 nuggets, and go back to the previous demonstration. So I can buy any number of nuggets greater than x. Maybe not the more elegant proof, but I think it's very visual.

OpenStudy (anonymous):

Once you have six consecutive answers, you know you can get the rest because 6 is the smallest unit of nuggets.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!