diff --git a/eating_cookies/eating_cookies.py b/eating_cookies/eating_cookies.py index 62655d803..856d49e4e 100644 --- a/eating_cookies/eating_cookies.py +++ b/eating_cookies/eating_cookies.py @@ -6,7 +6,23 @@ # a solution that is more efficient than the naive # recursive solution def eating_cookies(n, cache=None): - pass + total = 0 + print(n) + if n < 1: + print('base case: {}'.format(n)) + return 1 + if n-1 > 0: + print('minus 1: {}'.format(n)) + total += (1 + eating_cookies(n-1)) + if n-2 > 1: + print('minus 2: {}'.format(n)) + total += (1 + eating_cookies(n-2)) + if n-3 > 2: + print('minus 3: {}'.format(n)) + total += (1 + eating_cookies(n-3)) + + return total + if __name__ == "__main__": if len(sys.argv) > 1: diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index c845950c5..1b6a5110b 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -3,7 +3,15 @@ import math def recipe_batches(recipe, ingredients): - pass + batch_qty = [] + try: + for ing_r in recipe: + batches = ingredients[ing_r]//recipe[ing_r] + batch_qty.append(batches) + except KeyError as ke: + return 0 + + return min(batch_qty) if __name__ == '__main__': diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 9de20bc94..b0d715c8a 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -3,7 +3,14 @@ import argparse def find_max_profit(prices): - pass + current_mindex = 0 + + for i in range(0, len(prices)-1): + if prices[i] < prices[current_mindex]: + current_mindex = i + + return (max(prices[current_mindex+1:]) - prices[current_mindex]) + if __name__ == '__main__':