diff --git a/eating_cookies/eating_cookies.py b/eating_cookies/eating_cookies.py index 62655d803..4c314c708 100644 --- a/eating_cookies/eating_cookies.py +++ b/eating_cookies/eating_cookies.py @@ -6,7 +6,19 @@ # a solution that is more efficient than the naive # recursive solution def eating_cookies(n, cache=None): - pass + if cache is None: + cache = [0 for i in range(n+1)] + if n < 0: + return 0 + elif n >= 0 and n <= 1: + return 1 + elif cache[n] != 0: + return cache[n] + else: + answer = eating_cookies(n-1, cache) + eating_cookies(n-2, cache) + eating_cookies(n-3, cache) + cache[n] = answer + + return answer if __name__ == "__main__": if len(sys.argv) > 1: diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index c845950c5..d127f8530 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -3,8 +3,14 @@ import math def recipe_batches(recipe, ingredients): - pass - + max_batch = 1000 + for key, value in recipe.items(): + if key not in ingredients.keys() or value > ingredients[key]: + return 0 + pos_batch = math.floor(ingredients[key]/value) + if pos_batch < max_batch: + max_batch = pos_batch + return max_batch if __name__ == '__main__': # Change the entries of these dictionaries to test diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 9de20bc94..587c7d387 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -3,7 +3,16 @@ import argparse def find_max_profit(prices): - pass + cur_min = prices[0] + cur_max_profit = prices[1] - prices[0] + for i, x in enumerate(prices[:-1]): + if cur_min > x: + cur_min = x + for y in prices[i+1:]: + profit = y - cur_min + if profit > cur_max_profit: + cur_max_profit = profit + return cur_max_profit if __name__ == '__main__':