morgkl6
|
codepad
|
|
morgkl6
|
Saved pastes by morgkl6:
def subStringMatchExact(target, key): # Iterative function that prints the location(s) of a key string in a target string as a tuple.
isFound = True
location = 0 # Initial starting point (first item of target string)
x = 0 # x is the location where key is found in target
listOfLocations = [] # list of locations found
|
view (17 lines, 1 line of output) |
def subStringMatchExact(target, key): # Iterative function that prints the location(s) of a key string in a target string as a tuple.
isFound = True
location = 0 # Initial starting point (first item of target string)
x = 0 # x is the location where key is found in target
listOfLocations = [] # list of locations found
|
view (17 lines) |
def countSubStringMatchRecursive(target, key, count = 0): #Recursive function that counts instances of key in target
# by modifying the target string to include only the letters
|
view (17 lines, 1 line of output) |
keys_in_target = []
def countSubStringMatchRecursive(target, key): #Recursive function that counts instances of key in target
|
view (18 lines, 1 line of output) |
def count_sub_string_match(target, key): # finds location of key in target.
# Input is target string, key string and starting
# position on target string
count = 0
location = 0
|
view (14 lines, 1 line of output) |
#PS2, Q4
#iterative function that increases the value of total_mcnuggets tested in the nested "mcnuggets" function (which determine if the number is solvable by the Diophantine equation). The nested "mcnuggets" function is run (with increasing the input by 1 each time) until x numbers have been added to the "solvable" list (where x is equal to the number of mcnuggets in the smallest package). Once x numbers have been added to the "solvable" list, the differences between the last numbers added to the solvable list are. If each difference is 1 (i.e. all the numbers are consecutive), then this is the solution and the last number added to the "unsolvable" list is printed. If not all the differences are one, the input increases by 1 and the function starts over.
solvable = [0]
unsolvable = []
|
view (43 lines, 1 line of output) |
# 01/13/2012
# PS2,Q3: Program to calculate the highest number of mcnuggets that cannot be bought by packs of 6, 9 and 20
# contributor: morgkl6
solvable = [0] #list for number of mcnuggets that are evenly divisible
|
view (38 lines, 1 line of output) |
def mcnuggets(total_mcnuggets):
solution_found = False
for num6packs in range(0, total_mcnuggets/6+1):
for num9packs in range(0, (total_mcnuggets - 6*num6packs)/9+1):
num20packs = (total_mcnuggets - 9*num9packs - 6*num6packs)/20
|
view (11 lines, 5 lines of output) |