A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 5 years ago

I can get PS2 working, but solution is clumsy. Any suggestions on improvements? The snippet: int(math.ceil(target*1.0/pack2))+1 tries to find the max number of times we can include a package of size pack2, without exceeding the target. packages = (6,9,20) pack1 = packages[0] pack2 = packages[1] pack3 = packages[2] inattain = [] consec_attain = 0 for target in range(1,200): attain = False for ii in range(0,int(math.ceil(target*1.0/pack1))+1): for jj in range(0,int(math.ceil(target*1.0/pack2))+1): for kk in range(0,int(math.ceil(target*1.0/pack3))+1):

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

    if pack1*ii+pack2*jj+pack3*kk == target: #We can get it attain = True #End exhaustive search if not attain: inattain.append(target) consec_attain = 0 else: consec_attain += 1 if consec_attain == min(packages): break #End outer for print "Given package sizes, largest number that cannot be bought is: ", inattain.pop()

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

    To find the max number of times you can include pack2 in target, you can just use: target/pack2 I attached my ps2a.py for reference if you're interested.

    1 Attachment
  3. 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...


  • 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.