Skip to content

Instantly share code, notes, and snippets.

@rainyman2012
Last active December 31, 2021 17:18
Show Gist options
  • Save rainyman2012/5c626fcaa7e6e8e6a1587baf313f3485 to your computer and use it in GitHub Desktop.
Save rainyman2012/5c626fcaa7e6e8e6a1587baf313f3485 to your computer and use it in GitHub Desktop.
import numpy as np
day_price = np.array([[0,7], [1,12], [2,5], [3,3], [4,11], [5, 6], [6,10] ,[7,2], [8,0]])
results = np.zeros((9, 9))
print(results)
for buy in day_price:
for sell in day_price:
if buy[0] < sell[0]:
results[buy[0],sell[0]] = sell[1] - buy[1]
print(results)
all_results = np.where(results == np.max(results))
for res in list(zip(all_results[0], all_results[1])):
print("you should buy in", res[0], "and sell in", res[1], "your profit is", results[res])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment