ps2 problem 3- i am very close to the solution, but something just isn't going right inside my for loops. My problem set keeps skipping over every 3rd or so number after 50, when they should all work. The code is here, can someone please help me? Thanks! http://codepad.org/HxIuPz9j
first, i put in a print statement in the else clause - so the numbers in the right column fail the test in the inner for loop and the numbers in the left column have passed that test. one thing for sure you aren't skipping any numbers: http://codepad.org/Gq6znc9x then i wondered if it would make a difference which 'pack' was in the inner loop so i swapped twenty and six and got a different result. http://codepad.org/scvJPmnt that's kinda curious - i wouldn't think it would matter i looked closer at these numbers and saw that 30 is failing the test which is just plain wrong all the numbers before that looked ok. and one other thing - further down the list there are 6+ consecutive numbers in the left column - hmmm it shoulda stopped but didn't guess we need to print out the pack combinations: http://codepad.org/AoxcdKG0 hmmm i don't see anything interesting there what happens when nugnumb = 30? http://codepad.org/B56c6I4I hmmmm ..... http://codepad.org/cRPGHVmL how come the first time nugnumb equals thirty; sixnineandtwenty equal 1? and then http://codepad.org/AVcksTZ5 - it seems nine and twenty never equal zero when nugnumb equals 30. i may be on a wild goose chase - gotta think on it a bit
codepad seems to be down right now, but thanks for your input! ill look at it when codepad starts working again
hope that all didn't get lost = i'll wait a bit and then i think i can recreate it. but if you want, just start putting print statements in at strategic locations and then you can see what is happening and compare that to waht you thought was supposed to be happening.
haha i dont see why it would have gotten lost unless codepad has to change their web address, but thanks for your input, ill see if i can figure it out
i figured out what our problem was by looking at someone else's work. by defining the amount of nuggets and then adding one to that total if the for loops worked or didnt work, it somehow screwed up my system, although im not sure as to why. by saying for nuggetsnumber (i call it nugnumb in my code above) in range (1,100), it doesnt skip any numbers. again, im not sure why this works and the other one doesn't, but i'd love to know!
you were changing nugnumb inside the inner loop (if it satisfied the condition). when you did that- the for loops just kept on looping from their current status. so if the variables twenty, nine, six were 1 1 0 and nugnumb was twentynine, the condition would be satisfied and nugnumb -->> 30 BUT the pack combinations would start where they left off and 30 would never get tested against combinations between 0 0 0 and 1 1 0. i imagine that changing nugnumb in the inner loop was an optimization. sometimes it is better to write your code without optimizations, get it working, see if it is fast enuff, then proceed from there. those links above are working now. print statements are great debugging tools
my friend came to that same conclusion as well, but it is nice to have verification,because we were finding it hard to prove beyond doubt that that was the case. Thanks for your help! I have solved p3 on ps2 and am now bashing my brain against problem 4. Luck!
Join our real-time social learning platform and learn together with your friends!