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

Could someone please explain what is wrong with my Problem set 2 part 3? def solve(nugs): for a in range(0, (nugs/6)+1): for b in range(0, ((nugs-(a*6))/9)+1): c=(nugs-(a*6)-(b*9))/30 totnugs=6*a + 9*b + 30*c if totnugs==nugs: return(a, b, c) return(None, None, None) n=1 count=0 while count<6: n=n+1 if (None, None, None)==solve(n): count=0 else: count= count+1 print 'Largest number of McNuggets that cannot be bought in exact quantity: ',(n-7)

OpenStudy (anonymous):

please use dpaste.com (or something similar) to post your code. what happens when you run it? what kind of error do you get? does the traceback point to a certain line and hint at what the problem is? there aren't any comments in your code so it is hard to tell what you intended.

OpenStudy (anonymous):

You're right i should have posted comments. Sorry. Everytime solve(n) returns a value of none, none, none, count becomes 0. if solve(n) doesn't return a value of none none none, then count will go up 1. Once solve(n) returns an exact value 6 times in a row, count will become 6, the loop will stop, and n will be printed. When I try to run the program, it just runs forever

OpenStudy (anonymous):

My English its terrible but I will do my best. I think your trying to solve a problem whit no solution. Its posible to solve the ecuation 6*a+9*b+c*20=n because 20 , 6, 9 are relative primes, but your "solve" function is trying to solve the ecuation 6*a+9*b+c*30=n that ecuation has no solution for any n of the form n = 3n+2. Then your while loop will reset count to 0 every 3 steps

OpenStudy (anonymous):

Wow i figured it out...it's because I used 30 instead of 20. What a dumb mistake of me to make Thank you all for your help.

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!