diff --git a/eating_cookies/eating_cookies.py b/eating_cookies/eating_cookies.py index 62655d803..abaf58f6a 100644 --- a/eating_cookies/eating_cookies.py +++ b/eating_cookies/eating_cookies.py @@ -6,7 +6,29 @@ # a solution that is more efficient than the naive # recursive solution def eating_cookies(n, cache=None): - pass + if n < 0: + return 0 + elif n == 0: + return 1 + + return eating_cookies(n-1) + eating_cookies(n-2) + eating_cookies(n-3) + +cache = { + 0: 0, + 1: 1 +} + +def cookie_cache(n): + global cache + + if n in cache: + return cache[n] + + cache[n] = cookie_cache(n-1) + cookie_cache(n-2) + cookie_cache(n-3) + + return cache[n] + + if __name__ == "__main__": if len(sys.argv) > 1: diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index c845950c5..3fa39215e 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -4,7 +4,18 @@ def recipe_batches(recipe, ingredients): pass + min_num = 1000000 + for key in recipe: + if key in ingredients: + num_batches = ingredients[key] / recipe[key] + if num_batches < min_num: + min_num = int(num_batches) + + else: + min_num = 0 + + return min_num 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..ca2e38ff8 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -4,7 +4,15 @@ def find_max_profit(prices): pass + min_price = prices[0] + max_profit = prices[1] - min_price + for i in range(len(prices)): + for j in range(i + 1, len(prices)): + if prices[j] - prices[i] > max_profit: + max_profit = prices[j] - prices[i] + + return max_profit if __name__ == '__main__': # This is just some code to accept inputs from the command line