Skip to content

Commit

Permalink
age-on-planet exercise in elixir
Browse files Browse the repository at this point in the history
  • Loading branch information
davearonson committed Aug 4, 2016
1 parent f476349 commit 8ff17b7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions elixir/space-age/space_age.exs
@@ -0,0 +1,25 @@
defmodule SpaceAge do
@type planet :: :mercury | :venus | :earth | :mars | :jupiter
| :saturn | :neptune | :uranus

@seconds_per_earth_year 31557600
@orbit_seconds %{
mercury: 0.2408467 * @seconds_per_earth_year,
venus: 0.61519726 * @seconds_per_earth_year,
earth: 1.00000000 * @seconds_per_earth_year,
mars: 1.8808158 * @seconds_per_earth_year,
jupiter: 11.862615 * @seconds_per_earth_year,
saturn: 29.447498 * @seconds_per_earth_year,
uranus: 84.016846 * @seconds_per_earth_year,
neptune: 164.79132 * @seconds_per_earth_year,
}

@doc """
Return the number of years a person that has lived for 'seconds' seconds is
aged on 'planet'.
"""
@spec age_on(planet, pos_integer) :: float
def age_on(planet, seconds) do
seconds / @orbit_seconds[planet]
end
end

0 comments on commit 8ff17b7

Please sign in to comment.