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.1.0.8 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.1.0.7 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.1.0.6 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.1.0.5 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.1.0.4 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.1.0.3 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.1.0.2 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.1.0.1 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.1.0.0 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.55 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.54 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.53 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.52 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.51 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.50 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.49 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.48 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.47 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.46 tracks/scala/exercises/perfect-numbers/example.scala
trackler-2.0.8.45 tracks/scala/exercises/perfect-numbers/example.scala