i'm on ps2 and i understand whats needed im just not sure how to implement the code, i started to see if numbers can be evenly divided by 6,9,15,20,21,24,27,33 etc... basically everything that is a legitimated option to buy, but i can't figure out how to do it without this sloppy code. Any pointers??
Hoot! You just asked your first question! Hang tight while I find people to answer it for you. You can thank people who give you good answers by clicking the 'Good Answer' button on the right!
Have you made any progress on the code? If so, use dpaste to link it. If not, and you are not getting your head around how to start, then tell me what you understand about the numbers, ie, part 1...
I understand that since 50-55 have been proven, by adding 1 set of a or 6 to the set of 50 we get the next number. adding a to 51 gives us 57 and so on so every number is possible from the point of 5 consecutive possible choices in a row
this is the part im struggling with.. Test if there exists non-negative integers a, b, and c, such that 6a+9b+20c = n. (This can be done by looking at all feasible combinations of a, b, and c)
Okay, so, therefore, we have a way to stop iterations, ie, once you hit 6 in a row, you know that from that point on there is no point checking. Thus, you divise a way to iterate through the possibilities until you hit that... I used nested loops.
You've watched the video with the barnyard, I forget which it is, it's pretty much like that... but with added complexities.
no i dont think i saw the barnyard, that's in this class? must be lecture four and i havent gotten there yet, but thanks i'll keep trying it
I just looked, and I would guess it is, so far I prefer to watch the lecture which corresponds to when it is due, rather then set out, but, well, that's what works for me anyway. Use nested loops.
for loops
alright i understand the barnyard and nesting for loops but im still stuck on trying to figure out all the potential combinations from 1-200, heres what i have: def solve(nuggets): solutionFound = False n = 10 for small in range(0,n): for medium in range(0,n-small): large = n - small - medium totalNuggs = 6*small + 9*medium + 20*large print small, medium, large, totalNuggs if totalNuggs == nuggets: solutionFound = True if not solutionFound: print "No solution found!"
nvm, i think i finally figured it out
Join our real-time social learning platform and learn together with your friends!