Conversation
There was a problem hiding this comment.
Your first eating cookies solution only passes the small input tests because you are not using memoization. However, I noticed you have an improved version of the eating cookies solution that does not work with the provided unit tests. Please refactor your code by creating two separate eating cookies functions (one for small inputs and one for large inputs) that can be called by the unit tests.
|
Here is my solution of the eating cookies problem that does not use recursion: |
|
|
||
| def find_max_profit(prices): | ||
| pass | ||
| sorted_prices = sorted(prices) |
There was a problem hiding this comment.
As per the instructions, no sorting is allowed for this problem.
| @@ -3,8 +3,13 @@ | |||
| import math | |||
|
|
|||
| def recipe_batches(recipe, ingredients): | |||
There was a problem hiding this comment.
Nice work completing the recipe batches exercises! Here is my solution for the recipe batches problem:
def recipe_batches(recipe, ingredients):
min = None
for item, amount in recipe.items():
if item not in ingredients:
return 0
val = ingredients[item] // amount
if val == 0:
return 0
elif min == None or val < min:
min = val
return min
| @@ -3,12 +3,23 @@ | |||
| import sys | |||
|
|
|||
| def rock_paper_scissors(n): | |||
There was a problem hiding this comment.
Nice work completing the rock, paper, and scissors exercise! Here is my solution:
def rock_paper_scissors(n):
if n == 0:
return [[]]
choices = ['rock', 'paper', 'scissors']
main = []
def helper_func(main, start, end, copy):
if start == end:
return
new_cpy = copy[:]
for x in range(2):
helper_func(main, start + 1, n, new_cpy)
if new_cpy[start] == 'rock':
new_cpy[start] = 'paper'
elif new_cpy[start] == 'paper':
new_cpy[start] = 'scissors'
main.append(new_cpy[:])
helper_func(main, start + 1, n, new_cpy)
break
else:
new_cpy[start] = 'rock'
main.append(new_cpy[:])
for choice in choices:
copy = [choice] + ['rock'] * (n - 1)
main.append(copy)
helper_func(main, 1, n, copy)
return main
| # can kind of follow same set up as eating cookies | ||
| # getting from an initial value to zero! | ||
|
|
||
| def making_change(amount, denominations): |
There was a problem hiding this comment.
Nice work completing the making change exercise! Here is my solution:
def making_change(amount, denominations):
cache = { 0: 1 }
for a in range(denominations[0], amount + 1):
cache[a] = cache[a - denominations[0]]
for b in range(denominations[1], amount + 1):
cache[b] = cache[b] + cache[b - denominations[1]]
for c in range(denominations[2], amount + 1):
cache[c] = cache[c] + cache[c - denominations[2]]
for d in range(denominations[3], amount + 1):
cache[d] = cache[d] + cache[d - denominations[3]]
for e in range(denominations[4], amount + 1):
cache[e] = cache[e] + cache[e - denominations[4]]
return cache[amount]
MVP complete.