Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # equation: 6a + 9b + 12c
- # Equation is defined as the following:
- # x(a) + y(b) + z(c) = n
- # the goal is to determine what values of (a, b, c) are possible for given (x, y, z)
- def isComboPossible(n, x, y, z):
- for a in range(0, (n / x) + 1 ):
- for b in range (0, (n / y) + 1):
- for c in range (0, (n / z) + 1):
- #print 'a: ', a ,' b: ', b ,' c: ', c
- if((x * a) + (y * b) + (z * c)) == n:
- return (a, b, c)
- return False
- # theorem: if it is possible to buy a, a+1...a+5 nuggets then it is possible to buy all
- # combinations > a
- #
- # problem, given that the theorem is true find the highest possible combination that is NOT
- # possible
- def findHighestImpossibleCombo(x, y, z):
- currentHighest = 0 # stores failures as we come across them
- possibleCount = 0 # keeps track of how many tests are positive in a row
- comboNumberTest = 6; # start at the lowest possible combo of nuggets which is 6
- while possibleCount < 6:
- if isComboPossible(comboNumberTest, x, y, z) == False:
- currentHighest = comboNumberTest
- possibleCount = 0
- else:
- possibleCount = possibleCount + 1
- comboNumberTest = comboNumberTest + 1
- return currentHighest
- #number = int(raw_input("How Many?\n"))
- packageSizes = (6, 9, 20)
- #print 'PS2q1 TEST +++++++++++++++++++++++++++++++++\n\n\n'
- #chickenNuggetTest = isComboPossible(number, *packageSizes)
- #if chickenNuggetTest == False:
- # print '\nnot possible'
- #else:
- # print '\n6: ', chickenNuggetTest[0], '\n9: ', chickenNuggetTest[1], '\n20: ', chickenNuggetTest[2]
- #print '\n\n PSq4 TEST +++++++++++++++++++++++++++++++++++++\n\n\n'
- print 'The Highest possible combination using ', packageSizes[0] ,', ', packageSizes[1] ,',', packageSizes[2] ,' is ', findHighestImpossibleCombo(*packageSizes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement