Sha256: e3810d96b42eb1c40b62817e2b0a89f469f5f1bea6fade591c3c17063ec09466

Contents?: true

Size: 522 Bytes

Versions: 82

Compression:

Stored size: 522 Bytes

Contents

import NumberType.NumberType

object PerfectNumbers {
  def classify(n: Int): NumberType = {
    val sumOfFactors
    = (1 until n)
      .foldLeft(0)((acc, i) => if (n % i == 0) acc + i else acc)

    if (sumOfFactors < n)
      NumberType.Deficient
    else if (sumOfFactors > n)
      NumberType.Abundant
    else
      NumberType.Perfect
  }
}

object NumberType extends Enumeration {
  type NumberType = Value

  val Perfect = Value("Perfect")
  val Abundant = Value("Abundant")
  val Deficient = Value("Deficient")
}

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
trackler-2.0.8.44 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.43 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.42 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.41 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.40 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.39 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.38 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.37 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.36 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.35 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.34 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.33 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.32 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.31 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.30 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.29 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.28 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.27 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.26 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.24 tracks/scala/exercises/perfect-numbers/example.scala