What do you think about this code for problem 2?
nugget_pacs=(input("Package Size 1 "),input("Package Size 2 "),input("Package Size 3 ")) # tuople contains nugget package sizes tracker=[] # list which will hold possible combinations not_tracker=[] # list to hold combinations not possible for n in range(1,150): # range of numbers to consider as candidates can_buy=0 for a in range(0,(n/nugget_pacs[0])+1): for b in range(0,(n/nugget_pacs[1])+1): for c in range(0,(n/nugget_pacs[2])+1): if nugget_pacs[0]*a+nugget_pacs[1]*b+nugget_pacs[2]*c ==n: can_buy=1 tracker.append(n) # adds the possible combo to list if tracker.count(n)>1: # if statement to remove repeats tracker.remove(n) if can_buy==0: not_tracker.append(n) # adds value of n not possible to list print 'Possible Combinations are' ,tracker print 'These Combinations are not possible' , not_tracker
does it run? I do not get where you are taking nugget_pacs from?
woops mom
looks alright...if it runs an spits out good results it should be fine
# chickennuggets.py # dio equations ### ### template of code for Problem 4 of Problem Set 2, Fall 2008 ### bestSoFar = 0 # variable that keeps track of largest number # of McNuggets that cannot be bought in exact quantity pack = (6,9,20) # variable that contains package sizes lim=55 lima=lim/6 limb=lim/9 limc=lim/20 solution=False list=[] for n in range(1, lim+1): # only search for solutions up to size 150 ## complete code here to find largest size that cannot be bought ## when done, your answer should be bound to bestSoFar solution=False for a in range(lima+1): for b in range(limb+1): for c in range(limc+1): trialn=pack[0]*a+pack[1]*b+pack[2]*c if trialn==n: solution=True break if solution: break if solution: break if solution: savenws=n list.append(n) print n, "has a solution, being", a, b, c if len(list)==6: break else: print n, "does not have a solution" saven=n list=[] print saven, "largest without solution, given package size", pack But I already incorporated that sequence of six from the next assignment...but apart from that it is similar in logic...
also I did not save all possible combos...I took the first best and left
nugget_pacs is a tuople containing the size of the different packages which is taken in as input from the user. It then callc the specific package size by calling its index
Join our real-time social learning platform and learn together with your friends!