Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## 6a + 9b + 20c = N where N = totalNugs
- print "Please enter the desired number of chicken nuggets to test:"
- while True:
- try:
- totalNugs = int(raw_input())
- if totalNugs > 5:
- break
- elif totalNugs <= 5:
- print "Please enter a valid number of nuggets, 6 or more\n"
- except ValueError:
- print "Please enter a valid number of nuggets, 6 or more\n"
- ##Globalcounter to change the flow of the program after the first execution
- globalCount = 0
- rerun = True
- while rerun == True:
- a = 0
- b = 0
- c = 0
- aswap = 0
- bswap = 0
- cswap = 0
- ## get maximum values for a-b-c when all other variables equal 0.
- ## get atop
- atop = 0
- while (a*6) <= totalNugs:
- if (a*6) == totalNugs:
- aswap = a
- break
- else:
- a = a + 1
- atop = a - 1
- if aswap > atop:
- atop = aswap
- a = 0
- ## get btop
- btop = 0
- while (b*9) <= totalNugs:
- if (b*9) == totalNugs:
- bswap = b
- break
- else:
- b = b + 1
- btop = b - 1
- if bswap > btop:
- btop = bswap
- b = 0
- ## get ctop
- ctop = 0
- while (c*20) <= totalNugs:
- if (c*20) == totalNugs:
- cswap = c
- break
- else:
- c = c + 1
- ctop = c - 1
- if cswap > ctop:
- ctop = cswap
- c = 0
- ## Begin testing all possible combinations of 6(a->atop) + 9(b->btop) + 20(c->ctop) = totalNugs
- ## Global count = 0, First time run code.
- while globalCount == 0:
- foundCombination = False
- possibleCombinations = 0
- for i in xrange(atop + 1):
- for j in xrange(btop + 1):
- for k in xrange(ctop + 1):
- tempCheck = ((i*6) + (j*9) + (k*20))
- if tempCheck == totalNugs:
- possibleCombinations = possibleCombinations + 1
- foundCombination = True
- ## Break the loop and set globalCounter = 0 to execute 1st run code below
- globalCount = 2
- if globalCount == 2:
- globalCount = 0
- ## Second time run code, globalCounter = 1
- while globalCount == 1:
- foundCombination = False
- possibleCombinations = 0
- for i in xrange(atop + 1):
- for j in xrange(btop + 1):
- for k in xrange(ctop + 1):
- tempCheck = ((i*6) + (j*9) + (k*20))
- if tempCheck == totalNugs:
- print "It is possible to get " + str(totalNugs) + " nuggets by combining"
- print str(i) + " orders of 6, " + str(j) + " orders of 9, and " + str(k) + " orders of 20\n"
- possibleCombinations = possibleCombinations + 1
- foundCombination = True
- ## Program has completely finished now after a second time running and outputing possible combinations
- globalCount = 3
- if globalCount == 3:
- break
- rerun == False
- ## Runs only once upon first run, and skips after second run to list all possibilities
- if globalCount == 0:
- if foundCombination and possibleCombinations > 1:
- print "It is possible to get " + str(totalNugs) + " nuggets " + str(possibleCombinations) + " different ways"
- print "Would you like to see all of the possible ways to get " + str(totalNugs) + " nuggets? (Y/N)"
- while True:
- try:
- userFound1 = str(raw_input())
- if userFound1 == "Y" or userFound1 == "y":
- rerun = True
- globalCount = 1
- break
- elif userFound1 == "N" or userFound1 == "n":
- rerun = False
- break
- else:
- print "Please re-enter your decision in a acceptable format: (Y/N)"
- except ValueError:
- print "Please re-enter your decision in a acceptable format: (Y/N)\n"
- elif foundCombination and possibleCombinations == 1:
- print "It is possible to get " + str(totalNugs) + " nuggets " + str(possibleCombinations) + " way"
- print "Would you like to see all of the possible ways to get " + str(totalNugs) + " nuggets? (Y/N)"
- while True:
- try:
- userFound1 = str(raw_input())
- if userFound1 == "Y" or userFound1 == "y":
- rerun = True
- globalCount = 1
- break
- elif userFound1 == "N" or userFound1 == "n":
- rerun = False
- break
- else:
- print "Please re-enter your decision in a acceptable format: (Y/N)"
- except ValueError:
- print "Please re-enter your decision in a acceptable format: (Y/N)\n"
- elif foundCombination == False and totalNugs != 1:
- print "It is not possible to get " + str(totalNugs) + " nuggets by combining packs of 6, 9, and 20."
- rerun = False
Advertisement
Add Comment
Please, Sign In to add comment