From b756659c652b3ec38c5850002141741a7d4a9461 Mon Sep 17 00:00:00 2001 From: muamer Date: Wed, 19 Feb 2020 13:31:36 -0800 Subject: [PATCH 1/5] rps/stock --- rock_paper_scissors/rps.py | 33 +++++++++++++++++++++++++++++++-- stock_prices/stock_prices.py | 10 +++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/rock_paper_scissors/rps.py b/rock_paper_scissors/rps.py index 0fc53356e..0c4611a29 100644 --- a/rock_paper_scissors/rps.py +++ b/rock_paper_scissors/rps.py @@ -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__": diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 9de20bc94..2289019dd 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -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 From 2a1c056eafdb576006246821012e7a9f8676d443 Mon Sep 17 00:00:00 2001 From: muamer Date: Wed, 19 Feb 2020 14:38:02 -0800 Subject: [PATCH 2/5] eatin cookies --- eating_cookies/eating_cookies.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/eating_cookies/eating_cookies.py b/eating_cookies/eating_cookies.py index 62655d803..d4312af59 100644 --- a/eating_cookies/eating_cookies.py +++ b/eating_cookies/eating_cookies.py @@ -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: From 5fa6c661cd8ae323603b41b7d1c3f01b8bb33ef6 Mon Sep 17 00:00:00 2001 From: muamer Date: Wed, 19 Feb 2020 15:00:56 -0800 Subject: [PATCH 3/5] making change --- making_change/making_change.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/making_change/making_change.py b/making_change/making_change.py index 9adad4470..a812187c4 100644 --- a/making_change/making_change.py +++ b/making_change/making_change.py @@ -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__": From ae528af0cf31deda5d08f6ee8dad105259afcbbe Mon Sep 17 00:00:00 2001 From: muamer Date: Wed, 19 Feb 2020 15:43:02 -0800 Subject: [PATCH 4/5] reecipe --- recipe_batches/recipe_batches.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index c845950c5..4849d9562 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -3,12 +3,24 @@ 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 } + recipe = { 'milk': 2, 'sugar': 40, 'butter': 20 } + ingredients = { 'milk': 5, 'sugar': 120, 'butter': 500 } print("{batches} batches can be made from the available ingredients: {ingredients}.".format(batches=recipe_batches(recipe, ingredients), ingredients=ingredients)) \ No newline at end of file From 8af66c039fc951d24d0e0e245d6e2bb098cf5f93 Mon Sep 17 00:00:00 2001 From: muamer Date: Thu, 20 Feb 2020 16:29:10 -0800 Subject: [PATCH 5/5] mvp --- recipe_batches/recipe_batches.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index 4849d9562..3e77f2076 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -21,6 +21,7 @@ def recipe_batches(recipe, ingredients): if __name__ == '__main__': # Change the entries of these dictionaries to test # your implementation with different inputs - recipe = { 'milk': 2, 'sugar': 40, 'butter': 20 } - ingredients = { 'milk': 5, 'sugar': 120, 'butter': 500 } - print("{batches} batches can be made from the available ingredients: {ingredients}.".format(batches=recipe_batches(recipe, ingredients), ingredients=ingredients)) \ No newline at end of file + 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)) + \ No newline at end of file