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

my code for problem set 2b, just looking to have it critiqued/compared? http://dpaste.com/574622/

OpenStudy (anonymous):

Just run it, check the answer.If there is no problem,the remaining problem is efficiency. This is my code for the problem set 2. http://dpaste.com/575018/

OpenStudy (anonymous):

your comment in line 13 - why is it obvious that a, b, c <= 150?

OpenStudy (anonymous):

ya! right! what if i am bill gates and i order for my whole country... a b c will have to go beyond 150 in that case for sure.. :p

OpenStudy (anonymous):

it is obvious in this case because the assignment calls for N to go no higher than 150 (notice the main loop runs from 1 to 150), and so a, b, or c do not need to be higher than 150/a, 150/b, and 150/c, respectively. if i were Bill Gates and ordering for my whole country, the algorithm would need to be changed to reflect this; i.e. a, b, and c would not need to be bigger than the ratio of the population to a, b, and c.

OpenStudy (anonymous):

perhaps i misspoke here and in my code comments. i mean to say that a, b, and c do not need to be any higher than the ratio of 150 to a, b, and c's respective package sizes (default is 6, 9, and 20). that is to say, a does not need to be any higher than 150/6 because there's no way to have more than 150/6 units of 6 McNuggets that will go into 150 or fewer McNuggets.

OpenStudy (anonymous):

ya!! that is a reasonable answer ...so u should actually generalize that in your program.. i suggest u should try to get a user input on how many nuggets r actually required and then assign it to some variable x and then u can do x/a , x/b and x/c .. :)

OpenStudy (anonymous):

well all i've learned thus far, as far as user-input, is the raw_input function. while i could certainly accomplish what you suggest using that function's utility, i felt it was outside of the scope of this problem set's aim. i haven't yet reached the lecture that explains defining my own functions, but if i had, and this was an abstract function that i had created, then certainly this code would allow for the user/coder to set the upper bound of N--and, thus, the upper bound of a, b, and c. such functionality would not be that hard to incorporate. thank you for the input and suggestions :)

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!