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
21 changes: 19 additions & 2 deletions eating_cookies/eating_cookies.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
#!/usr/bin/python

# 0: eat 0 cookies 1 time
# 1: eat 1 cookie 1 time
# 2: eat 1 cookie 1 time
# 2: eat 2 cookies
# 3: eat 1 cookie 1 time, eat 1 cookie 1 time, eat 1 cookie 1 time

import sys

# The cache parameter is here for if you want to implement
# a solution that is more efficient than the naive
# recursive solution
def eating_cookies(n, cache=None):
pass

if n < 0:
return 0
if n == 0:
return 1
elif cache and cache[n] > 0:
return cache[n]
else:
if cache is None:
cache = {}
value = eating_cookies(n - 1, cache) + eating_cookies(n - 2, cache) + eating_cookies(n - 3, cache)
cache[n] = value
return value

if __name__ == "__main__":
if len(sys.argv) > 1:
num_cookies = int(sys.argv[1])
Expand Down
18 changes: 17 additions & 1 deletion making_change/making_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@

import sys

cache = {1:1}

def making_change(amount, denominations):
pass

if amount in cache:
return cache[amount]
totalWays = 0

for d in denominations:
if d <= amount:
totalWays += making_change(amount-d, denominations) + making_change(amount, denominations)

cache[amount] = totalWays
return totalWays

print(cache)
print(making_change(10,[1, 5, 10, 25, 50]))



if __name__ == "__main__":
Expand Down
13 changes: 12 additions & 1 deletion recipe_batches/recipe_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
import math

def recipe_batches(recipe, ingredients):
pass
batch_size = None
for recipe_ing, recipe_cnt in recipe.items():
if recipe_ing in ingredients:
ingredient_cnt = ingredients[recipe_ing]
maximum = int(ingredient_cnt / recipe_cnt)
if batch_size == None or maximum < batch_size:
batch_size = maximum
else:
return 0

return batch_size or 0



if __name__ == '__main__':
Expand Down
15 changes: 14 additions & 1 deletion rock_paper_scissors/rps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@

import sys

import pprint
def rock_paper_scissors(n):
pass
throws = ['rock', 'paper', 'scissors']

allPlays = [[]]
for i in range(n):
newPlays = []
for play in allPlays:
# three times below:
for throw in throws:
newPlay = play + [throw]
newPlays.append(newPlay)
allPlays = newPlays

return allPlays


if __name__ == "__main__":
Expand Down
16 changes: 14 additions & 2 deletions stock_prices/stock_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
import argparse

def find_max_profit(prices):
pass

lowest = prices[0]
highest = prices[0]
maximum = None
for price in prices[1:]:
diff = price - lowest
if maximum == None or diff > maximum:
maximum = diff
if price > highest:
highest = price
if price < lowest:
lowest = price

return maximum


if __name__ == '__main__':
# This is just some code to accept inputs from the command line
Expand Down