Skip to content
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
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/Algorithms.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions eating_cookies/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions eating_cookies/.idea/eating_cookies.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions eating_cookies/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions eating_cookies/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions eating_cookies/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions eating_cookies/lecture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def naive_fib(n):
if n == 0: return 0
if n == 1: return 1

return naive_fib(n - 1) + naive_fib(n - 2)

def cashe_fib(n):
cache = {0:0, 1:1}

def cashe_fib_inner(n):
nonlocal cache

# if n == 0: return 0
# if n == 1: return 1
#
if n not in cache:
cashe[n] = cache_fib(n - 1) + cache_fib(n - 2)

return cache[n]

for i in range(10):
print(cashe_fib(i))
2 changes: 2 additions & 0 deletions recipe_batches/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions recipe_batches/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions recipe_batches/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions recipe_batches/.idea/recipe_batches.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions recipe_batches/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion recipe_batches/recipe_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ def recipe_batches(recipe, ingredients):
# 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))
print("{batches} batches can be made from the available ingredients: {ingredients}.".format(batches=recipe_batches(recipe, ingredients), ingredients=ingredients))





2 changes: 2 additions & 0 deletions stock_prices/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions stock_prices/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions stock_prices/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions stock_prices/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions stock_prices/.idea/stock_prices.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions stock_prices/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions stock_prices/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]

[requires]
python_version = "3.7"
109 changes: 102 additions & 7 deletions stock_prices/stock_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,109 @@

import argparse

def find_max_profit(prices):
pass
# THIS CODE WORKS UNLESS LAST NUMBER IS THE MOST PROFIT

# def find_max_profit(prices):
# max_profit = [0]
#
# for i in range(0, len(prices) - 1):
# cur_index = i
#
# for x in range(cur_index + 1, len(prices) - 1):
#
# if prices[x] - prices[cur_index] > max_profit[0]:
# max_profit[0] = prices[x] - prices[cur_index]
#
#
#
# elif prices[x] - prices[cur_index] < 0 and max_profit[0] == 0:
# max_profit[0] = prices[x] - prices[cur_index]
#
# return max_profit[0]
# print('maxprofit')
# print(find_max_profit([100, 55, 4, 98, 10, 18, 90, 95, 43, 11, 47, 67, 89, 42, 49, 79, 10000]))

def find_max_profit(prices):
current_min_price_so_far = prices[0]
profit = prices[0]
for price in prices:
print(price)
if price - current_min_price_so_far > profit and prices.index(price) != 0:
profit = price - current_min_price_so_far
if price < current_min_price_so_far:
current_min_price_so_far = price
return profit
print('maxprofit')
print(find_max_profit([2,5,7,8,2,7,1,8,3,100,1000]))

if __name__ == '__main__':
# This is just some code to accept inputs from the command line
parser = argparse.ArgumentParser(description='Find max profit from prices.')
parser.add_argument('integers', metavar='N', type=int, nargs='+', help='an integer price')
args = parser.parse_args()
# This is just some code to accept inputs from the command line
parser = argparse.ArgumentParser(description='Find max profit from prices.')
parser.add_argument('integers', metavar='N', type=int, nargs='+', help='an integer price')
args = parser.parse_args()

print("A profit of ${profit} can be made from the stock prices {prices}.".format(
profit=find_max_profit(args.integers), prices=args.integers))

# Lambda Problem Solving Framework

# UPER

# U - UNDERSTAND
# P - PLAN
# E - EXECUTE
# R - REFLECT

# UNDERSTAND
# PROBLEM ---
# GET LIST OF NUMBERS EX: 4, 34, 6, 5, 574, 4
# the max profit is computed by subtracting some price by another
# price that comes before it; it can't come after it in the list of prices.

# GOAL
# GOING THRU LIST LEFT TO RIGHT, BUY AT LOW NUMBER, SELL AT HIGH NUMBER
# find the maximum difference between the smallest and largest prices
#
#
#
#
# EXPECTED RESULTS:
#
# INPUT - [4, 5, 100, 10]
# OUTPUT - 95
#
# INPUT - [90, 5, 1, 100]
# OUTPUT - 99

# INPUT - [3, 10, 5, 10]
# OUTPUT - 7

# sudo
# if first item in array = a is smaller then 2nd = b,
# then return b - a
# else repeat on b and c
# then c and d
# until end of array

# REFLECT
# IS THIS EFFICIENT
#

# if first item in array = a is smaller then 2nd = b,
# end = len(prices)
# for i in range(0, end):
# for j in range(0, end - 1):
# if prices[i] < prices[j]:
# # then return b - a
# arr = []
# j.append(arr)
# x = max(arr)
# return x
#
# else:
# print("don't buy")

print("A profit of ${profit} can be made from the stock prices {prices}.".format(profit=find_max_profit(args.integers), prices=args.integers))
# else repeat on b and c
# then c and d
# until end of array
# return largest number