Skip to content

Instantly share code, notes, and snippets.

@simsicon simsicon/time.rb
Last active Aug 29, 2015

Embed
What would you like to do?
Relative Time Dilation
#
# http://en.wikipedia.org/wiki/Time_dilation
#
C = 300000.0
SECONDS_IN_YEAR = 365 * 24 * 3600
def calculate(v, delta_t)
relative_v = ( v * v ) / ( C * C )
denominator = Math.sqrt( 1 - relative_v ).to_f
numerator = delta_t.to_f
numerator / denominator
end
def output(*args)
result = calculate(*args)
%Q[
Travel in space at speed of #{ args[0].to_f } m/s
for #{ ( args[1] / SECONDS_IN_YEAR ).to_f } years
the relative time dilation would be #{ ( result / SECONDS_IN_YEAR ) } years.
]
end
args = [ ( 1 / 3.0 ) * C, 20 * SECONDS_IN_YEAR ] # 1/3 C for 20 years
puts output(*args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.