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.38 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.37 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.36 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.35 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.34 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.33 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.32 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.31 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.30 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.29 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.28 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.27 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.26 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.25 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.24 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.23 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.22 tracks/scala/exercises/space-age/example.scala
trackler-2.2.1.21 tracks/scala/exercises/space-age/example.scala