Skip to content
This repository was archived by the owner on Jul 18, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.7"
108 changes: 100 additions & 8 deletions eating_cookies/eating_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,103 @@
# a solution that is more efficient than the naive
# recursive solution
def eating_cookies(n, cache=None):
pass

if __name__ == "__main__":
if len(sys.argv) > 1:
num_cookies = int(sys.argv[1])
print("There are {ways} ways for Cookie Monster to eat {n} cookies.".format(ways=eating_cookies(num_cookies), n=num_cookies))
else:
print('Usage: eating_cookies.py [num_cookies]')
combinations = 0

if n == 0:
return 1

def fact(num):
if num < 1:
factorial = 0
else:
factorial = 1
while num >= 1:
factorial *= num
num -= 1
return factorial

# print('factorial check:', fact(3))

nums = [1, 2, 3]


# how many ways can you make combos with one number
for i in nums:
# print(f'starting {i}')
if (n / i) >= 1 and n % i == 0:
# print(f'1 number: {i}')
combinations += 1

print('combinations for 1:', combinations)

# how many ways can you make combos with 2 numbers
two_num_combos = []
for i in nums:
for j in nums:
if i != j:
if i + j <= n:
if [j,i] not in two_num_combos:
two_num_combos.append([i,j])

print('two num combos',two_num_combos)
print('solving equation for 2 num')

for i in two_num_combos:
# xi[0] + yi[1] = n
# solve the equation
y = 1
x_range = n // i[0] + 1
y_range = n // i[1] + 1

print('x range', x_range)
print('y range', y_range)


for x in range(1, x_range):
for y in range(1, y_range):
if x*i[0] + y*i[1] == n:
print(x * [i[0]], y * [i[1]])
print(f'x:{x}, y:{y}')
combinations += fact(x+y)// (fact(x)*fact(y))

print('fact',fact(x+y)//2)


# how many ways can you make combos with 3 numbers
three_num_combos = []

if sum(nums) <= n:
three_num_combos.append(nums)

for i in three_num_combos:
# xi[0] + yi[1] + zi[2] = n
# solve the equation

x_range = n // i[0] + 1
y_range = n // i[1] + 1
z_range = n // i[2] + 1

print('x range', x_range)
print('y range', y_range)
print('z range', z_range)


for x in range(1, x_range):
for y in range(1, y_range):
for z in range(1, z_range):
if x*i[0] + y*i[1] + z*i[2]== n:
print(x * [i[0]], y * [i[1]], z * [i[2]])
print(f'x:{x}, y:{y}, z:{z}')
combinations += fact(x+y+z)// (fact(x)*fact(y)*fact(z))


return combinations

print(eating_cookies(0))

# if __name__ == "__main__":
# if len(sys.argv) > 1:
# num_cookies = int(sys.argv[1])
# print("There are {ways} ways for Cookie Monster to eat {n} cookies.".format(ways=eating_cookies(num_cookies), n=num_cookies))
# else:
# print('Usage: eating_cookies.py [num_cookies]')
24 changes: 23 additions & 1 deletion recipe_batches/recipe_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,29 @@
import math

def recipe_batches(recipe, ingredients):
pass

max_batches = 2 ** 100

batches = {}
for i in recipe:
# print(i)
try:
batches[i] = ingredients[i] // recipe[i]
except:
print(f'{i} not in ingredients')
return 0

for i in batches.values():
if i < max_batches:
max_batches = i

return max_batches

recipe = { 'milk': 100, 'butter': 50, 'flour': 5 }
ingredients = { 'milk': 132, 'butter': 48, 'flour': 51 }
print(recipe_batches(recipe, ingredients))




if __name__ == '__main__':
Expand Down
25 changes: 24 additions & 1 deletion stock_prices/stock_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,31 @@
import argparse

def find_max_profit(prices):
pass
# make a variable to hold current max profit
max_profit = -2 ** 100

# set cursor at index 1
# we want to sell after we bought
cur = 1

for i in range(len(prices)):
cur = i + 1

while cur < len(prices):
profit = prices[cur] - prices[i]

if profit > max_profit:
max_profit = profit

cur += 1

return max_profit



print("Finding max profit")
prices = [1050, 270, 1540, 3800, 2]
print(find_max_profit(prices))

if __name__ == '__main__':
# This is just some code to accept inputs from the command line
Expand Down