A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 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):
anonymous
 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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0if 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()

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0To 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.
Ask your own question
Sign UpFind more explanations on OpenStudy
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
 Engagement 19 Mad Hatter
 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.