Sha256: 42ad68f48146265022b478ff840091b33afeb3c1f8088e8ba2e8a29161bc0d52

Contents?: true

Size: 1.3 KB

Versions: 158

Compression:

Stored size: 1.3 KB

Contents

object SpaceAge {
  private val daysToEarthAge = 365.25
  private val daysToMercuryAge = 87.969
  private val daysToVenusAge = 224.701
  private val daysToMarsAge = 686.971
  private val daysToJupiterAge = 4332.59
  private val daysToSaturnAge = 10759.22
  private val daysToUranusAge = 30799.095
  private val daysToNeptuneAge = 60190.03

  private def toEarthDays(seconds: Double): Double = {
    val minutes = seconds.toDouble / 60
    val hours = minutes / 60
    hours / 24
  }

  private def toPlanetAge(daysToPlanetAge: Double, seconds: Double): Double =
    round(toEarthDays(seconds) / daysToPlanetAge)

  private def round(value: Double): Double = (value * 100).round / 100.0

  def onEarth(seconds: Double): Double = toPlanetAge(daysToEarthAge, seconds)
  def onMercury(seconds: Double): Double = toPlanetAge(daysToMercuryAge, seconds)
  def onVenus(seconds: Double): Double = toPlanetAge(daysToVenusAge, seconds)
  def onMars(seconds: Double): Double = toPlanetAge(daysToMarsAge, seconds)
  def onJupiter(seconds: Double): Double = toPlanetAge(daysToJupiterAge, seconds)
  def onSaturn(seconds: Double): Double = toPlanetAge(daysToSaturnAge, seconds)
  def onUranus(seconds: Double): Double = toPlanetAge(daysToUranusAge, seconds)
  def onNeptune(seconds: Double): Double = toPlanetAge(daysToNeptuneAge, seconds)
}

Version data entries

158 entries across 158 versions & 1 rubygems

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