From 20342824e4f7632ce9e6c8dd411986a6ae4b10ca Mon Sep 17 00:00:00 2001 From: Ayomide Jones Date: Wed, 19 Feb 2020 16:47:45 +0100 Subject: [PATCH 1/6] pseudocode and algorithms for stock_prices set up --- stock_prices/stock_prices.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 9de20bc94..8a41e0a81 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -1,9 +1,39 @@ #!/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 + +find_max_profit([1050, 270, 1540, 3800, 2]) should return 3530 + +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)): + + + if __name__ == '__main__': From 3445393f31e5dd738f3436acb550376d7d47b45d Mon Sep 17 00:00:00 2001 From: Ayomide Jones Date: Wed, 19 Feb 2020 17:52:24 +0100 Subject: [PATCH 2/6] stock_prices.py resolved --- stock_prices/stock_prices.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 8a41e0a81..2fe56f78c 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -30,8 +30,13 @@ def find_max_profit(prices): profit = [] + print(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) + print(profit) + return max(profit) From d3e1e08a1f703aabd761b1612fdc85ef899eac03 Mon Sep 17 00:00:00 2001 From: Ayomide Jones Date: Wed, 19 Feb 2020 18:04:06 +0100 Subject: [PATCH 3/6] removed trailing print statements --- stock_prices/stock_prices.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 2fe56f78c..5e6ac0330 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -30,12 +30,11 @@ def find_max_profit(prices): profit = [] - print(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) - print(profit) + return max(profit) From e590927357f455fbdea8a2cff2a3eed1356aae53 Mon Sep 17 00:00:00 2001 From: Ayomide Jones Date: Thu, 20 Feb 2020 21:59:01 +0100 Subject: [PATCH 4/6] eating cookies resolved and tested --- eating_cookies/eating_cookies.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/eating_cookies/eating_cookies.py b/eating_cookies/eating_cookies.py index 62655d803..24d1a7467 100644 --- a/eating_cookies/eating_cookies.py +++ b/eating_cookies/eating_cookies.py @@ -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: From 084549ffb9e7fb40655a9910d5e49927bb75ae0f Mon Sep 17 00:00:00 2001 From: Ayomide Jones Date: Thu, 20 Feb 2020 22:56:23 +0100 Subject: [PATCH 5/6] recipe batches solved and tested --- recipe_batches/recipe_batches.py | 25 +++++++++++++++++++++++-- stock_prices/stock_prices.py | 2 -- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index c845950c5..81da27599 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -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 diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 5e6ac0330..aaa59def6 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -7,8 +7,6 @@ return max_profit from a single buy and sell order of trade: buy first before selling -find_max_profit([1050, 270, 1540, 3800, 2]) should return 3530 - diff btw smallest and largest prices max_profit = some price - another price that comes before it From 715cd0d3f5c82a5c255be6d058682f73350f9699 Mon Sep 17 00:00:00 2001 From: Ayomide Jones Date: Fri, 21 Feb 2020 00:15:22 +0100 Subject: [PATCH 6/6] rps task completed --- rock_paper_scissors/rps.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/rock_paper_scissors/rps.py b/rock_paper_scissors/rps.py index 0fc53356e..0fc0c2dd1 100644 --- a/rock_paper_scissors/rps.py +++ b/rock_paper_scissors/rps.py @@ -1,9 +1,30 @@ #!/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__": @@ -11,4 +32,4 @@ def rock_paper_scissors(n): num_plays = int(sys.argv[1]) print(rock_paper_scissors(num_plays)) else: - print('Usage: rps.py [num_plays]') \ No newline at end of file + print('Usage: rps.py [num_plays]')