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