Created
February 4, 2011 10:26
-
-
Save workmad3/810965 to your computer and use it in GitHub Desktop.
Transcription of https://github.com/holtzermann17/mathgame/blob/master/snowman.py into ruby
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
# 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