Skip to content

Comments

Algorithms project submission#1

Open
bcabanayan wants to merge 10 commits intomasterfrom
bruce-cabanayan
Open

Algorithms project submission#1
bcabanayan wants to merge 10 commits intomasterfrom
bruce-cabanayan

Conversation

@bcabanayan
Copy link
Owner

@bcabanayan bcabanayan commented May 29, 2019

MVP complete.

@eddygonzalez9708 eddygonzalez9708 self-requested a review June 11, 2019 03:06
Copy link
Collaborator

@eddygonzalez9708 eddygonzalez9708 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@eddygonzalez9708
Copy link
Collaborator

Here is my solution of the eating cookies problem that does not use recursion:

def eating_cookies(n, cache=None):
  if cache == None:
    cache = [0 for i in range(n + 1)]
  
  if n == 0 or n == 1:
    return 1
  elif n == 2:
    return 2

  cache[0] = 1
  cache[1] = 1
  cache[2] = 2

  for num in range(3, n + 1):
    cache[num] = sum(cache[num - 3:num])
  
  return cache[n]


def find_max_profit(prices):
pass
sorted_prices = sorted(prices)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the instructions, no sorting is allowed for this problem.

@@ -3,8 +3,13 @@
import math

def recipe_batches(recipe, ingredients):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants