Skip to content

Instantly share code, notes, and snippets.

@mrdougwright
Last active August 29, 2015 14:04
Show Gist options
  • Save mrdougwright/792d7dcb992d832dafe6 to your computer and use it in GitHub Desktop.
Save mrdougwright/792d7dcb992d832dafe6 to your computer and use it in GitHub Desktop.
Apple Stock
arr = [20,30,50,40,100,10,45,95,30,10]
def low_high(stock_prices)
max = 0
stock_prices.each_with_index do |x, index|
current_max = 0
stock_prices[index..-1].each do |y|
current_max = y - x
if current_max > max
max = current_max
low = x
high = y
end
end
end
puts "low num: #{low} high num: #{high}"
end
low_high(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment