Created
June 11, 2020 18:47
-
-
Save violetguos/102bc02fdbeca41f8d9f308ba2ebe810 to your computer and use it in GitHub Desktop.
stonk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stonk_picker(stonk_arr) | |
# find the max diff between elements | |
max_profit = 0 | |
max_idx = [0, 0] | |
stonk_arr.each_with_index do |buy, buy_idx| | |
stonk_arr.each_with_index do |sell, sell_idx| | |
# puts "%d %d" % [buy_idx, sell_idx] | |
if buy_idx < sell_idx && sell - buy > max_profit | |
max_idx[0] = buy_idx | |
max_idx[1] = sell_idx # get original idx | |
max_profit = sell - buy | |
end | |
end | |
end | |
return max_idx | |
end | |
puts stonk_picker([17,3,15,6,9,8,6,1,10]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment