Would someone mind breaking down the math for problem set 2 Question 1-3-4 for me? I wrote this program http://pastebin.com/u4Dac2gK thinking that it just wanted to know if the number given was a solution or not but it seems that I was mistaken. The part I am not understanding is the math, so I do not know how to map the problem into python.
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!
looks like you have the math correct you 'generate' different combinations of i, j, k and use those variables in the nugget equation and compare the result to the number you are looking for.
have you tried to write out in words what you are trying to do? that usually helps.
ine 19: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#testing-for-truth-values
your code looks like it is doing lots of stuff - can you walk us through what it does (generally)?
Yeah sure I would be happy to. I am not having a problem with the code itself, I am having a problem working with the question. Maybe the math is over my head, but I dont understand what exactly the goal for each question is.
Breaking the code down step by step, I first take the input for any number of nuggets, which I will test to see if it is possible to generate somehow. The next thing I do is basically solve for each variable while all other variables equal zero. something like 6(a) +9(0) + 20(0) = N... From that I can determine the maximum possible amount of 1 package which can reach the specified N from the user. Then I repeat this for the other two variables to get the maximum number of boxes for each user input N.
From here I have my baseline, 0 0 0, and my maximum values, atop btop ctop, from which I will generate all possible permutations to see if N is possible. If it is possible, foundCombination is set to true, and the user interfaces with the program to either find out that the program has found a match or it has not.
Then the user decides whether they would want to view all possible combinations or not by selecting Y/N which sets the while loop rerun either to true or false to run again. Then all of the permutations are printed out for the user to view.
All the while I have a thing called a globalCounter that I am using to control the flow of the program. While it is running, I assign different values to globalCounter at specific times to get different blocks of code to be carried out each time the rerun loop runs. By the second time, the program cuts out all of the code using the globalCounter except for the code that generates all possible permutations and then prints it out. Then the program exits.
If it was hard to follow I am sorry, but if you run the code you should understand it pretty quickly.
Like I said though, I am not having much of a problem with the coding aspect now, I am having a problem understanding what exactly the question is asking to do, and then mapping that to the program. Unless what I did is what they are asking for, but I do not think this is the case. Sorry for the confusion and let me know if I can clear anything up.
Your code is probably right, but I think your solution is unduly complicated.
For example, the whole code searching for atop, btop, ctop could be replaced by three lines;
atop = totalNugs / 6
btop = totalNugs / 9
ctop = totalNugs / 20
After that, you're doing very intricated things to find all the possible combinations to by totalNugs. It's not in the assignment. The question is 'is it possible ?'. Period.
So first you should simplify the code to test if a given number satisfies the constraints. After that, write code that walks through all integers, when it finds 6 consecutive integers ok -> it is done and prints the last nok integer.
Not the answer you are looking for? Search for more explanations.
I believe you are correct about the complicated code, it probably could have been written much easier, as you showed me in three lines. The last thing you said, "when it finds 6 consecutive integers ok -> it is done and prints the last nok integer." This is the part I am not understanding. What does this have to do with finding whether not a given number is achievable with some combination of the three packages? Are you saying that after a certain number, all past that number are achievable?
That's where the theorem and the problem 2 enter the scene.
The thorem says that if we can x such as it is possible to buy x, x + 1, ..., x + 5 nuggets, then it is possible for any integer >= x. Another way to say it is if we find 6 consecutive integers satisfying the requirements, then it is possible for all the larger integers.
I understand what it means now, that's what I was having problems with. So essentially anything over the number 50 will have a possible solution. Interestingly enough, using my program that calculates all possible solutions, I actually came up with a graph depiction of the theorem. It turns out that around 2250 nuggets to test, it is possible to get more solutions than the given number and then sky rockets into 10's of thousands of solutions... See the attachment following this post. It shows from 500 - 10,000 the possible solutions there are to make the given N, and then plots it out in a graph which looks to be getting exponentially bigger... If you are interested.