diff --git a/eating_cookies/eating_cookies.py b/eating_cookies/eating_cookies.py index 62655d803..951dbc67e 100644 --- a/eating_cookies/eating_cookies.py +++ b/eating_cookies/eating_cookies.py @@ -6,7 +6,18 @@ # a solution that is more efficient than the naive # recursive solution def eating_cookies(n, cache=None): - pass + count = 0 + + if n == 0 or n ==1: + return 1 + elif n==2: + return 2 + else: + arr = [1,1,2] + for number in range(3, n+1): + count = arr[-3]+arr[-2]+arr[-1] + arr.append(count) + return count if __name__ == "__main__": if len(sys.argv) > 1: diff --git a/making_change/making_change.py b/making_change/making_change.py index 9adad4470..dc8f21fb1 100644 --- a/making_change/making_change.py +++ b/making_change/making_change.py @@ -2,9 +2,18 @@ import sys +total = 0 +count = 0 +sub_count = 1 + def making_change(amount, denominations): - pass + test = [1] + [0] * (amount) + + for index in denominations: + for place in range(index, amount + 1): + test[place] = test[place] + test[place - index] + return test[amount] if __name__ == "__main__": # Test our your implementation from the command line diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index c845950c5..f96c32a16 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -3,7 +3,25 @@ import math def recipe_batches(recipe, ingredients): - pass + batches = -1 + no_more_ingredients = False + + while no_more_ingredients == False: + batches +=1 + + for item in recipe: + if item in ingredients.keys(): + if recipe[item] <= ingredients[item]: + ingredients[item] -= recipe[item] + else: + no_more_ingredients = True + break + else: + no_more_ingredients = True + break + # break + + return batches if __name__ == '__main__': diff --git a/rock_paper_scissors/rps.py b/rock_paper_scissors/rps.py index 0fc53356e..66dd560cd 100644 --- a/rock_paper_scissors/rps.py +++ b/rock_paper_scissors/rps.py @@ -1,10 +1,32 @@ #!/usr/bin/python - +# merge([1,3,5,7], [2,4,6,8]) +# [1,2,3,4,5,6,7,8] import sys +def rps_recursion(number, list): + if number == 0: + return number + + def rock_paper_scissors(n): - pass + result_array = [] + selection = ['rock', 'paper', 'scissors'] + + def recursive_listing(iterations, result=[]): + if iterations == 0: + return result_array.append(result) + for choice in selection: + recursive_listing(iterations -1, result + [choice]) + + recursive_listing(n) + return result_array + + + + return return_list + +rock_paper_scissors(2) if __name__ == "__main__": if len(sys.argv) > 1: diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 9de20bc94..bf6dd3e11 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -3,7 +3,19 @@ import argparse def find_max_profit(prices): - pass + max_profit = 0 + stored_value = prices[0] + max_profit = prices[1]-prices[0] + index = 2 + while True: + if index > len(prices): + break + for price in prices[index-1:]: + if price - stored_value > max_profit: + max_profit = price - stored_value + stored_value=prices[index-1] + index += 1 + return max_profit if __name__ == '__main__':