Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created February 4, 2011 10:26
Show Gist options
  • Save workmad3/810965 to your computer and use it in GitHub Desktop.
Save workmad3/810965 to your computer and use it in GitHub Desktop.
# Decrease height along an asymptote (3 / x + 1)
def update(height, time)
height - 3.0/(time+1.0)
end
# Initial height
initial_height = current_height = 10.0
# run the simulation 15 times
heights = (0...15).map do |time|
current_height = update(current_height, time)
end
# Put time0 value at the start of the array
heights.unshift(initial_height)
# Output
puts "time | height"
heights.each_with_index do |height, time|
time_str = time.to_s
puts " " + time_str + (" " * (5 -time_str.length)) + "| " + height.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment