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

how to list all combinations? (pset2-problem1) problem set 2 problem 1 specifies that all combinations of nuggets should be listed but mine only lists the first one it finds, how can i fix this? http://dpaste.com/714822/

OpenStudy (anonymous):

I think your loops aren't quite working the way you want them to...Take a look at this code: http://dpaste.com/714840/ I added a 'while' loop to call your function so it will run through a number of values for numNuggets. Also, I moved your print statement up in the loop so you can see what is happening as your program loops through the different values. When you are debugging it is always a good idea to print results at various stages so you can analyze what is going on inside your code. Looking at it I would make 2 comments: 1) Would you consider setting the ninePacks up on a 'for' loop like the others? I think this might give you better results for that variable in particular. 2) Be careful of the range function...It will only go up to the number before the ending value, so when you say range(0, numNuggets/6) notice how when numNuggets == 24, the sixPacks stop at 3! This is an easy fix, luckily, just add 1: range(0, 1+numNuggets/6)

OpenStudy (anonymous):

add another for loop for ninePacks - print combinations http://codepad.org/F7TnNcoc print combinations that equal numNuggets: http://codepad.org/NL1msGGz you need to remember that the range function will not include the limiting value - if you want numbers from zero to ten, inclusive, you must specify range(0, 11). found and xtra answer by increasing the ranges http://codepad.org/RPuFhb6C I don't know why but i like to have the small one in the inner loop (spins fastest) and the big one in the outer loop (spins slowest) - like an odometer - makes no difference for the answer: http://codepad.org/BB3BYaFj

OpenStudy (coolguy123):

this is the code i did for this problem http://dpaste.com/716668/ hope it helps

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!