Skip to content
This repository was archived by the owner on Jul 18, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion eating_cookies/eating_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions recipe_batches/recipe_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion stock_prices/stock_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down