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

I'm doing PS2 problem 4. My program gives me a list of values which can't be obtained from boxes of 6,9,and 20 Mcnuggets. How do I make my program only print the last (i.e. the highest) value? http://codepad.org/08nyijrk

OpenStudy (anonymous):

put all the can't-be-boughts in a list and print the last one http://pastebin.com/32LkCpsg everytime a number can't be bought, save it and keep track of consecutive can-be-boughts - when you get to 6, the last number you saved as cannot be bought should be the highest

OpenStudy (anonymous):

Attached is my answer to Problem Set 2 (Part I) Hope this helps.

OpenStudy (anonymous):

pelikan: This is my solution to Problem Set 2 (Part IV). As bwCA explained you need to keep the highest value in bestSoFar. In my code I inserted a check so that the bestSoFar is only replaced if a larger number is discovered. I'm not sure whether this was necessary. Hope this helps.

OpenStudy (anonymous):

I have changed my code. for some reason i get a time out error for 200 McNuggets but if I change it to approx 50 it works. http://codepad.org/IsJxFqZy . Thanks for sending your code I'm going to take a look at it now

OpenStudy (anonymous):

I changed the code again and it works now. http://codepad.org/8SucYGFW . Thanks a lot for the advice!!

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!