Skip to content
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
24 changes: 23 additions & 1 deletion eating_cookies/eating_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions recipe_batches/recipe_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions stock_prices/stock_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down