Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

kd1510

Hello, I am doing the mcnuggets 2008 fall problem set, and am struggling as to how I would write a program to solve the equation can anyone help me?

  • one year ago
  • one year ago

  • This Question is Open
  1. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    equation?

    • one year ago
  2. kd1510
    Best Response
    You've already chosen the best response.
    Medals 0

    6a + 9b + 20c = n. Problem 1. Show that it is possible to buy exactly 50, 51, 52, 53, 54, and 55 McNuggets, by finding solutions to the Diophantine equation. You can solve this in your head, using paper and pencil, or writing a program. However you chose to solve this problem, list the combinations of 6, 9 and 20 packs of McNuggets you need to buy in order to get each of the exact amounts.

    • one year ago
  3. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    wat's n?

    • one year ago
  4. kd1510
    Best Response
    You've already chosen the best response.
    Medals 0

    n is the number of nuggets

    • one year ago
  5. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    a b c ?

    • one year ago
  6. kd1510
    Best Response
    You've already chosen the best response.
    Medals 0

    the different combinations of packets of nuggets you can buy (packet a has 6, b has 9 c has 20)

    • one year ago
  7. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    so a b c are no of packets bought of each type?

    • one year ago
  8. kd1510
    Best Response
    You've already chosen the best response.
    Medals 0

    yes

    • one year ago
  9. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    u can find the maximum number of packets bought for each type? say for 51 the max number of packets is 51/6

    • one year ago
  10. A.Avinash_Goutham
    Best Response
    You've already chosen the best response.
    Medals 0

    brute force method use three for loops to the combination now that u kno the limits of every type

    • one year ago
  11. kd1510
    Best Response
    You've already chosen the best response.
    Medals 0

    ok that makes sense, but how would I create a program that lists every single combination

    • one year ago
  12. kd1510
    Best Response
    You've already chosen the best response.
    Medals 0

    and what was your reasoning behind wanting to figure out the maximum number of packets? it wouldnt occur to me... i was just trying to program every combination into the code

    • one year ago
  13. RoamingBlue
    Best Response
    You've already chosen the best response.
    Medals 1

    @kd1510 the reasoning behind wanting to know the maximum number of each size is so you know what numbers each of your for loops should traverse. totals = (50, 51, 52, 53, 54, 55) for total in totals: # find the max a where b and c are zero maxA = total/6 # find the max b where a and c are zero maxB = total/9 # find the max c where a and b are zero maxC = total/20 # preset a variable to indicate if we were able to solve solutionPossible = False # Loop through all possible combinations for i in range(0, maxA): for j in range(0, maxB): for k in range(0, maxC): if (i*6 + j*9 + k*20 == total): print str(total) + " solved: a=" + str(i) +" b=" + str(j) + " c=" + str(k) solutionPossible = True break if (solutionPossible == False): print str(total) + " couldn't be solved" ########################################## So what you want to do (for this brute force method that is), is: Find the maximum number of each of the packets there could possibly be (because you don't want or need to loop more than that). Then, loop through all the possibilities. You want to check from zero (because there might have been zero of that packet) all the way up to the max, for every combination.

    • one year ago
    • Attachments:

See more questions >>>

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.