Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

pseudocode and algorithms for stock_prices set up #272

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
22 changes: 21 additions & 1 deletion eating_cookies/eating_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@
# a solution that is more efficient than the naive
# recursive solution
def eating_cookies(n, cache=None):
pass
#base cases
if n < 0:
return 0

elif n == 0:
return 1

# if cache exist and contains the answer
elif cache and cache[n] > 0:
return cache[n]

else:
# does cache exist? if not ccreate a cache
if not cache:
cache = {i: 0 for i in range(n + 1)}

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
25 changes: 23 additions & 2 deletions recipe_batches/recipe_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,31 @@

import math

def recipe_batches(recipe, ingredients):
pass
"""
function parameters recipe = {}, ingredients = {}
ingredient {
name: amount
}
recipe {
ingredient_name: amt available
}

return max



"""

def recipe_batches(recipe, ingredients):
for key in recipe.keys():
if key in ingredients:
recipe[key] = ingredients[key] // recipe[key]
if recipe[key] == 0:
break
else:
recipe[key] = 0
return min(recipe.values())

if __name__ == '__main__':
# Change the entries of these dictionaries to test
# your implementation with different inputs
Expand Down
25 changes: 23 additions & 2 deletions rock_paper_scissors/rps.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
#!/usr/bin/python
"""
output =[]
first pass
output=[[rock], [paper], [scissors]]
second pass
output=[[rock, rock], [rock,paper], [rock,scissors], [paper, rock], [paper, paper], [
paper,scissors], [scissors,rock], [scissors,paper], [scissors,scissors]]

base case accounts for the number of plays
in recursive calls to append to the inner lists

"""
import sys


def rock_paper_scissors(n):
pass
rps = ['rock', 'paper', 'scissors']
plays = []
def rock_paper_scissors_helper(options,n):
if n == 0:
plays.append(options)
else:
for item in rps:
rock_paper_scissors_helper(options + [item], n - 1 )
rock_paper_scissors_helper([],n)
return plays


if __name__ == "__main__":
if len(sys.argv) > 1:
num_plays = int(sys.argv[1])
print(rock_paper_scissors(num_plays))
else:
print('Usage: rps.py [num_plays]')
print('Usage: rps.py [num_plays]')
34 changes: 33 additions & 1 deletion stock_prices/stock_prices.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
#!/usr/bin/python
"""
bot buys and sells amazon stocks
function find_max_profit (prices)
prices = []

return max_profit from a single buy and sell
order of trade: buy first before selling

diff btw smallest and largest prices
max_profit = some price - another price that comes before it

current_min_price_so_far =
max_profit_so_far =

Algorithm
profit = []
iterate through stock prices
keep track of lowest price
subtract lowest price from current item(i)
append result of subttaction to profit list
find the maximum profit using max() method


"""

import argparse

def find_max_profit(prices):
pass
profit = []
for i in range (0, len(prices)):
for j in range (i + 1, len(prices)):
price_diff = prices[j] - prices[i]
profit.append(price_diff)

return max(profit)




if __name__ == '__main__':
Expand Down