Created
May 24, 2009 21:40
-
-
Save jotto/117271 to your computer and use it in GitHub Desktop.
This file contains 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
# first arg is goal time in either seconds or ##:## | |
# second arg is distance in meters (optional) | |
# EXAMPLE ruby running_pace.rb 15:30 5000 | |
class Float | |
def seconds_to_minutes | |
"#{self.to_i/60}:#{(self.to_f%60.0).rjust}" | |
end | |
def rjust | |
self.to_i.to_s.rjust(2,"0") | |
end | |
end | |
goal_time_in_seconds = ARGV[0] | |
total_meters = ARGV[1].to_f > 0.0 ? ARGV[1].to_f : 5_000.0 | |
raise "Need to pass goal time in seconds or in ##:##" if goal_time_in_seconds.nil? || goal_time_in_seconds.to_i == 0 | |
if goal_time_in_seconds.to_s =~ /:/ | |
minutes,seconds = goal_time_in_seconds.split(":") | |
goal_time_in_seconds = minutes.to_f*60.0 + seconds.to_f | |
else | |
goal_time_in_seconds = goal_time_in_seconds.to_f | |
end | |
meters_per_second = total_meters / goal_time_in_seconds.to_f | |
split_200 = 200.0 / meters_per_second | |
split_400 = 400.0 / meters_per_second | |
split_600 = 600.0 / meters_per_second | |
split_800 = 800.0 / meters_per_second | |
split_1609 = 1609.0 / meters_per_second | |
puts "goal time for #{total_meters} meters is #{goal_time_in_seconds.seconds_to_minutes} or #{goal_time_in_seconds} seconds" | |
puts "200m splits are #{split_200}" | |
puts "400m splits are #{split_400} or #{split_400.seconds_to_minutes}" | |
puts "600m splits are #{split_600} or #{split_600.seconds_to_minutes}" | |
puts "800m splits are #{split_800.seconds_to_minutes}" | |
puts "1609m splits are #{split_1609.seconds_to_minutes}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment