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
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
Attached is my answer to Problem Set 2 (Part I) Hope this helps.
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.
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
I changed the code again and it works now. http://codepad.org/8SucYGFW . Thanks a lot for the advice!!
Join our real-time social learning platform and learn together with your friends!