Sha256: 0710310ecd597edfe599b75c3c63b9d5b03afe263577654b914092e97f598f31

Contents?: true

Size: 701 Bytes

Versions: 396

Compression:

Stored size: 701 Bytes

Contents

local SpaceAge = {}

SpaceAge.EARTH_ORBITAL_PERIOD = 31557600
SpaceAge.ORBITAL_PERIODS = {
  earth = 1.0,
  mercury = 0.2408467,
  venus = 0.61519726,
  mars = 1.8808158,
  jupiter = 11.862615,
  saturn = 29.447498,
  uranus = 84.016846,
  neptune = 164.79132
}

local function round(val, decimal)
  local exp = 10 ^ decimal
  return math.ceil(val * exp - 0.5) / exp
end

function SpaceAge:new(seconds)
  self.__index = self
  local meta_tbl = { seconds = seconds }
  for k, v in pairs(SpaceAge.ORBITAL_PERIODS) do
    local val = round(seconds / SpaceAge.EARTH_ORBITAL_PERIOD / v, 2)
    meta_tbl['on_' .. k] = load('return ' .. val)
  end

  return setmetatable(meta_tbl, self)
end

return SpaceAge

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.179 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.178 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.177 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.176 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.175 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.174 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.173 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.172 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.171 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.170 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.169 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.167 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.166 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.165 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.164 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.163 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.162 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.161 tracks/lua/exercises/space-age/example.lua
trackler-2.2.1.160 tracks/lua/exercises/space-age/example.lua