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

Ok I started to move on, but wanted to finish up ps2_4. I pretty much have it, but for some reason, I can't get the 20piece to come up to be added to 6 piece or 9 piece. It has to be something simple... so simple it evades me. Can anyone help me out? http://codepad.org/ZyNL4F1s

OpenStudy (anonymous):

hmmm, you made that pretty complicated. it is really hard to tell what is going on. however, you have a break at line thirty-one that has the same indentation as your your 'for b...' statement (line twenty-three). looks like that will cause the c loop to 'stop' - this will not let c go to the next c.

OpenStudy (anonymous):

could you advise me in how to make it less complicated? i actually thought it was more explanatory than I have done in the past, but that doesn't mean anything if it's still confusing. Are you referring to the code, the comments, or the whole thing? Thanks!

OpenStudy (anonymous):

it is hard to follow how the execution will flow - i stopped trying to figure it out here is one way, http://codepad.org/HuCBmLMg

OpenStudy (anonymous):

i think i just try to keep it simple and don't try to optimize the code for efficiency. after i get it to run correctly, if it is tooo slow, i go back and tweak it

OpenStudy (anonymous):

Nice! thanks for the feedback

OpenStudy (anonymous):

hi! i have just written another solution. it is longer than the one posted by bwCA - but it is bound to run faster, since avoids the 3 nested for loops, and actually skips the rest of the exhaustive search once one combination is found. i do not think that efficiency should be much of a concern at this stage of the course... anyway i was surprised about how different solutions we came up with! http://codepad.org/4zrsw27u

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!