Created
December 9, 2015 19:39
Revisions
-
edenthecat created this gist
Dec 9, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ def getMaxProfit(stock_prices_yesterday) if stock_prices_yesterday.index(stock_prices_yesterday.min) < stock_prices_yesterday.index(stock_prices_yesterday.max) max_profit = (stock_prices_yesterday.max - stock_prices_yesterday.min) else possible_profits = [] minIndex = 0 maxIndex = stock_prices_yesterday.length stock_prices_yesterday[0...(maxIndex-1)].each do |i| stock_prices_yesterday[minIndex...maxIndex].each do |j| possible_profits.push(j - i) end minIndex += 1 end max_profit = possible_profits.max end puts "max profit: " + max_profit.to_s end getMaxProfit([11, 10, 9, 8, 7])