Ps2 q3 help,
i was struggling with how to work this one out so i looked at how others had done it, unfortunately it has not helped.
I am not sure how to get it to try all other combanations.
My code is at the top and the sample i worked from which works is at the bottom
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
I don't understand what you're doing inside the while loops. Could you explain ?
I am not sure of the maths so the nested for loop at the top to work out the pack size is confusing to me.
The code works out the pack size and then that is added to a list, from that i thought if i checked the last one and the one 6 before that to see if they are consecutive then the one 7th before the end was the answer.
I noticed with print that there was duplicates and it was not putting them in order so i removed dups with set then ordered them again but still no joy which was when i posted.
After that i ran it through the debugger and found that it does not work out them in order so i have to check from the beginning each time.
I now have it working if you could explain the math or give me feedback on my code that would be very helpful.
OK I understand the first part of your code now. For each number of nuggets: you enumerate all the combinations of a, b, c that could potentially give you the number and you calculate how many nuggets it would really give.
I must say I don't really understand the second part. Seems pretty complicated to me.
Not the answer you are looking for? Search for more explanations.
Your program seems to produce the right results, but I must say I've never thought this problem could be solved this way. The 'standard' way is the following:
1. Write code to test if it is possible to buy a given number of nuggets
2. Enumerate through positive integers. For each, use the preceding code. If we can find 6 consecutive integers that are ok, the solution is the last non ok number