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
13 changes: 11 additions & 2 deletions eating_cookies/eating_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
# 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
def eating_cookies(n, cache={1: 1}):

if n < 0:
return 0
if n == 0:
return 1
if n not in cache:
cache[n] = eating_cookies(n - 1, cache) + eating_cookies(n - 2, cache) + eating_cookies(n - 3, cache)
return cache[n]



if __name__ == "__main__":
if len(sys.argv) > 1:
Expand Down
12 changes: 11 additions & 1 deletion making_change/making_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
import sys

def making_change(amount, denominations):
pass
cache = [0 for i in range(amount+1)]
cache[0] = 1
print(cache)
#check all coins
for coin in denominations:
# set conditions for all values from value of coin till amount + 1
for i in range(coin, amount + 1):
# add number of combinations to value in cache
cache[i] = cache[i] + cache[i-coin]
print(cache)
return cache[amount]


if __name__ == "__main__":
Expand Down
21 changes: 17 additions & 4 deletions recipe_batches/recipe_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
import math

def recipe_batches(recipe, ingredients):
pass
max_batch = 0
counter = 0
for i in recipe:
print(f"{max_batch} max batch")
try:
batches = ingredients[i] // recipe[i]
print(f"{batches} batches")
except:
batches = 0
if counter == 0 or batches <= max_batch:
max_batch = batches
counter += 1
return max_batch


if __name__ == '__main__':
# Change the entries of these dictionaries to test
# your implementation with different inputs
recipe = { 'milk': 100, 'butter': 50, 'flour': 5 }
ingredients = { 'milk': 132, 'butter': 48, 'flour': 51 }
print("{batches} batches can be made from the available ingredients: {ingredients}.".format(batches=recipe_batches(recipe, ingredients), ingredients=ingredients))
recipe = { 'milk': 2}
ingredients = { 'milk': 200 }
print("{batches} batches can be made from the available ingredients: {ingredients}.".format(batches=recipe_batches(recipe, ingredients), ingredients=ingredients))

33 changes: 31 additions & 2 deletions rock_paper_scissors/rps.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
#!/usr/bin/python

import sys

validPlays = [["rock"], ["paper"], ["scissors"]]
def rock_paper_scissors(n):
pass
if n == 0:
return [[]]
if n == 1:
return validPlays

output = []

arrA = rock_paper_scissors(n - 1)

for subArr in arrA:
for play in validPlays:
newPlay = subArr + play
output.append(newPlay)

return output


# def generate(arr, index, result):
# if index == len(arr):
# print(arr)
# result.append(list(arr))
# return arr


# for item in ("rock", "paper", "scissors"):
# arr[index] = item
# generate(arr, index+1, result)

# print(rock_paper_scissors(4))



if __name__ == "__main__":
Expand Down
10 changes: 9 additions & 1 deletion stock_prices/stock_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
import argparse

def find_max_profit(prices):
pass
profit = prices[1] - prices[0]
cost = prices[0]

for p in prices[1:]:
if (p - cost) > profit:
profit = p - cost
if p < cost:
cost = p

return profit

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