A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

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.

  • This Question is Closed
  1. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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)?

  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  3. maitre_kaio
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  4. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

  5. maitre_kaio
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  6. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  7. maitre_kaio
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It is a classic result, since the number of combinations grows exponentially with the number. Nice work to show it visually.

  8. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for the help maitre_kaio

  9. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.