Created
September 25, 2022 19:47
-
-
Save vKxni/9e1eef2f5afc321fe773dd5e2b6d62d7 to your computer and use it in GitHub Desktop.
Returns the number of years a person that has lived for 'seconds' seconds is aged on 'planet'
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
defmodule Utils.SpaceAge do | |
@type planet :: | |
:mercury | |
| :venus | |
| :earth | |
| :mars | |
| :jupiter | |
| :saturn | |
| :uranus | |
| :neptune | |
@doc """ | |
Returns 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 | |
earth_years = seconds / 31557600 | |
case planet do | |
:mercury -> earth_years / 0.2408467 | |
:venus -> earth_years / 0.61519726 | |
:earth -> earth_years | |
:mars -> earth_years / 1.8808158 | |
:jupiter -> earth_years / 11.86215 | |
:saturn -> earth_years / 29.447498 | |
:uranus -> earth_years / 84.016846 | |
:neptune -> earth_years / 164.79132 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment