Abundant, deficient and perfect number classifications: Difference between revisions
Content added Content deleted
Line 373: | Line 373: | ||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
<lang Scala>def properDivisors(n: Int) = (1 to n/2).filter(i => n % i == 0) |
<lang Scala>def properDivisors(n: Int) = (1 to n/2).filter(i => n % i == 0) |
||
def |
def classifier(i: Int) = properDivisors(i).sum compare i |
||
val groupNames = Vector("Deficient", "Perfect", "Abundant") |
val groupNames = Vector("Deficient", "Perfect", "Abundant") |
||
val |
val groups = (1 to 20000).groupBy( classifier ) |
||
val groups = divisors.groupBy(divider) |
|||
groups.foreach( v => println(groupNames(v._1 + 1) + ": " + v._2.length) )</lang> |
groups.foreach( v => println(groupNames(v._1 + 1) + ": " + v._2.length) )</lang> |
||
{{out}} |
{{out}} |