Skip to content

Instantly share code, notes, and snippets.

@simsicon
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simsicon/11324090 to your computer and use it in GitHub Desktop.
Save simsicon/11324090 to your computer and use it in GitHub Desktop.
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