diff --git a/eating_cookies/eating_cookies.py b/eating_cookies/eating_cookies.py index 62655d803..518cae4f9 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..b887056fe 100644 --- a/making_change/making_change.py +++ b/making_change/making_change.py @@ -2,8 +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__": diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index c845950c5..09b584312 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -3,8 +3,24 @@ 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 + + return batches if __name__ == '__main__': # Change the entries of these dictionaries to test diff --git a/rock_paper_scissors/rps.py b/rock_paper_scissors/rps.py index 0fc53356e..68c818354 100644 --- a/rock_paper_scissors/rps.py +++ b/rock_paper_scissors/rps.py @@ -2,9 +2,22 @@ import sys -def rock_paper_scissors(n): - pass +validMoves = [['rock'], ['paper'], ['scissors']] +def rock_paper_scissors(n) + if n == 0: + return [[]] + if n == 1: + return validMoves + + output = [] + arr = rock_paper_scissors(n -1) + for subArr in arr: + for move in validMoves: + newMove = subArr + move + output.append(newMove) + + return output if __name__ == "__main__": if len(sys.argv) > 1: diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 9de20bc94..3108d5f12 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -3,7 +3,24 @@ import argparse def find_max_profit(prices): - pass + if len(prices) < 2: + return 0 + + # set intial lowest and maxProfit values from array values + lowest = prices[0] + maxProfit = prices[1] - prices[0] + + # for each item in prices + for i in range(1, len(prices)): + price = prices[i] + # each new item, find out the difference from the current item and the lowest prev price + profitFromTrade = price - lowest + # track the lowest price + lowest = min(lowest, price) + # save the max, positive difference + maxProfit = max(profitFromTrade, maxProfit) + # return max when finished + return maxProfit if __name__ == '__main__':