Skip to content

Instantly share code, notes, and snippets.

@codenoid
Created January 16, 2020 17: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 codenoid/7f0fa4e7fee4224e8b910de6e8db7160 to your computer and use it in GitHub Desktop.
Save codenoid/7f0fa4e7fee4224e8b910de6e8db7160 to your computer and use it in GitHub Desktop.
package space
import "math"
type Planet string
var orbitalPeriod = map[string]float64{
"Mercury": 0.2408467,
"Venus": 0.61519726,
"Earth": 1.0,
"Mars": 1.8808158,
"Jupiter": 11.862615,
"Saturn": 29.447498,
"Uranus": 84.016846,
"Neptune": 164.79132,
}
func Age(age float64, planet Planet) float64 {
second := make(map[string]float64)
for key, value := range orbitalPeriod {
// value * (365*24*60*60)
second[key] = value * 3.154e+7
}
age = age / second[string(planet)]
return math.Round(age*100) / 100
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment