Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 30 Online
OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
ShadowKid3: what are examples of a class three lever?
17 hours ago 3 Replies 2 Medals
alphaXtiger: Help pls
1 day ago 3 Replies 1 Medal
danielfootball123: What are good stocks to invest
2 days ago 3 Replies 0 Medals
Burro: 5(5x+7)+3(x+3)
2 days ago 13 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!