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: 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__": diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index c845950c5..3e77f2076 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -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)) \ 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 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