Last active
June 24, 2016 02:37
-
-
Save 13steinj/7e98d2ce2f4e864e313543ddfcd33571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
n = 1 # potential number of nuggets to be bought | |
bestSoFar = [] # that keeps track of largest number of McNuggets that cannot be bought in exact quantity | |
packages = [6,9,20] # list that contains package sizes | |
count = 0 # of times 'n' test has returned True | |
count_limit = 6 # limit to n, n+1,...,n+5 theorem, if 6 consecutive numbers are True then all after are True. | |
def check_if_purchasable(potential, package_list): | |
for a in range(math.ceil(potential/package_list[0])): # test all size '6' package purchase amounts up to multiplers resulting in greater than test number nugget amounts, min 1 | |
for b in range(math.ceil(potential/package_list[1])): # test all size '9' package purchase amounts up to multiplers resulting in greater than test number nugget amounts, min 1 | |
for c in range(math.ceil(potential/package_list[2])): # test all size '20' package purchase amounts up to multiplers resulting in greater than test number nugget amounts, min 1. | |
if ((package_list[0]*a)+(package_list[1]*b)+(package_list[2]*c) == potential): # check if test amounts equal the goal amount | |
return True # that goal has been reached | |
return False # that goal has not been reached | |
# nugget_problem | |
while count < count_limit: # check if count has reached limit for n, n+1,...,n+5 theorem. | |
if check_if_purchasable(n, packages): # if goal was reached | |
count += 1 # add to count for n, n+1,...,n+5 theorem, if 6 consecutive numbers are True then all after are True. | |
else: # if goal was not reached | |
bestSoFar.append(n) # save test as non purchasable amount of nuggets | |
count = 0 # reset count | |
n += 1 # set next number to test | |
print ("Largest number of McNuggets that cannot be bought in exact quantity: " + str(bestSoFar[-1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment