Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Program to see what is the largest number that can not be derived from when ordering Chicken McNuggets in
- #6pc, 9pc, 20pc sizes. This checks every possible case and develops a list of possible combinations
- #then examines what numbers are not on that list to find the largest number you can't buy.
- #James Tuvell
- #Feb-1-12
- bestSoFar = 0
- packages = (6,9,20)
- endtest = 150
- listcombos = []
- #checkChicken
- #input numb is the number to be checked
- #a,b,c are the 3 possible piece counts a=6pc b=9pc c=20pc
- #output None
- #checks weather a combination is possible.
- def checkChicken (numb,a,b,c):
- combine=(packages[0]*a)+(packages[1]*b)+(packages[2]*c)
- if combine == numb:
- print (numb, "is a combination of ", a, b, c, " times ", packages[0], packages[1], packages[2])
- if numb not in listcombos:
- listcombos.append(numb)
- return
- #main routine
- #Not much here. I chose a nested while loop and reduced the number of iterations by
- #dividing the test size by the piece count giving the maximum number of pieces that
- #could be giving in that size. This reduces the load considerably.
- i = 1
- while i <= endtest:
- a = 0
- while a <= endtest/packages[0]:
- b = 0
- while b <= endtest/packages[1]:
- c=0
- while c <= endtest/packages[2]:
- checkChicken(i,a,b,c)
- c=c+1
- b=b+1
- a=a+1
- i=i+1
- print ("finished")
- print ("The list of possibilities up to ",i-1, "that can be bought are ", listcombos)
- #this is the section that checks for missing number on the sucess list. That will show
- #which ones were failures and what is the largest of them.
- for q in range (1, endtest):
- if q not in listcombos:
- bestSoFar=q
- print (bestSoFar, "is not in the list")
- print "The highest number you can not make with 6pc 9pc and 20pc mcnuggets is:",bestSoFar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement