From 4fa28c2e942cc1eacaf8ac59e61e6a86b839af0d Mon Sep 17 00:00:00 2001 From: Akak Almazbekova Date: Wed, 19 Feb 2020 15:06:39 -0800 Subject: [PATCH 1/4] add stock-prices --- stock_prices/stock_prices.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 9de20bc94..668a55e81 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -3,7 +3,23 @@ import argparse def find_max_profit(prices): - pass + lowest = prices[0] + highest = prices[0] + maximum = None + for price in prices: + if price > highest: + highest = price + potential_profit = highest - lowest + if maximum is None or potential_profit > maximum: + maximum = potential_profit + if price < lowest: + lowest = price + + return maximum + + + + if __name__ == '__main__': From 1cd9a982e94e29d15e4b8cdad36b0dc0db3fac1a Mon Sep 17 00:00:00 2001 From: Akak Almazbekova Date: Wed, 19 Feb 2020 23:34:32 -0800 Subject: [PATCH 2/4] Day 1 MVP done --- eating_cookies/eating_cookies.py | 6 +++++- recipe_batches/recipe_batches.py | 13 ++++++++++++- stock_prices/stock_prices.py | 8 ++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/eating_cookies/eating_cookies.py b/eating_cookies/eating_cookies.py index 62655d803..73ef7045f 100644 --- a/eating_cookies/eating_cookies.py +++ b/eating_cookies/eating_cookies.py @@ -6,7 +6,11 @@ # a solution that is more efficient than the naive # recursive solution def eating_cookies(n, cache=None): - pass + if n == 1: return 1 + total = 0 + for i in range (n): + total = eating_cookies(i + 1) + eating_cookies(n - (i + 1)) + return total if __name__ == "__main__": if len(sys.argv) > 1: diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index c845950c5..ca97b6749 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -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__': diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 668a55e81..7fee6137c 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -6,12 +6,12 @@ def find_max_profit(prices): lowest = prices[0] highest = prices[0] maximum = None - for price in prices: + for price in prices[1:]: + diff = price - lowest + if maximum == None or diff > maximum: + maximum = diff if price > highest: highest = price - potential_profit = highest - lowest - if maximum is None or potential_profit > maximum: - maximum = potential_profit if price < lowest: lowest = price From 12aabc87cfef2c8a42d3c7b1a06fc308146de711 Mon Sep 17 00:00:00 2001 From: Akak Almazbekova Date: Thu, 20 Feb 2020 11:04:45 -0800 Subject: [PATCH 3/4] eating_cookies done --- eating_cookies/eating_cookies.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/eating_cookies/eating_cookies.py b/eating_cookies/eating_cookies.py index 73ef7045f..7fa65322f 100644 --- a/eating_cookies/eating_cookies.py +++ b/eating_cookies/eating_cookies.py @@ -1,17 +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): - if n == 1: return 1 - total = 0 - for i in range (n): - total = eating_cookies(i + 1) + eating_cookies(n - (i + 1)) - return total - + 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]) From a11f0dc2bc6d635d138e4a7c9401ef79464be538 Mon Sep 17 00:00:00 2001 From: Akak Almazbekova Date: Thu, 20 Feb 2020 19:46:30 -0800 Subject: [PATCH 4/4] rps done --- making_change/making_change.py | 18 +++++++++++++++++- rock_paper_scissors/rps.py | 15 ++++++++++++++- stock_prices/stock_prices.py | 4 ---- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/making_change/making_change.py b/making_change/making_change.py index 9adad4470..7670e629d 100644 --- a/making_change/making_change.py +++ b/making_change/making_change.py @@ -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__": diff --git a/rock_paper_scissors/rps.py b/rock_paper_scissors/rps.py index 0fc53356e..b21001c44 100644 --- a/rock_paper_scissors/rps.py +++ b/rock_paper_scissors/rps.py @@ -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__": diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 7fee6137c..17f3aa2f8 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -17,10 +17,6 @@ def find_max_profit(prices): return maximum - - - - if __name__ == '__main__': # This is just some code to accept inputs from the command line