Abundant, deficient and perfect number classifications: Difference between revisions

Scala solution
No edit summary
(Scala solution)
Line 370:
Deficient: 15043 Perfect: 4 Abundant: 4953
</pre>
 
=={{header|Scala}}==
<lang Scala>def properDivisors(n: Int) = (1 to n/2).filter(i => n % i == 0)
def divider(divisors: (Int, Seq[Int])) = divisors._1.compare(divisors._2.sum)
val groupNames = Vector("Deficient", "Perfect", "Abundant")
val divisors = (1 to 20000).map( i => (i, properDivisors(i)) )
val groups = divisors.groupBy(divider)
groups.foreach( v => println(groupNames(v._1 + 1) + ": " + v._2.length) )</lang>
{{out}}
<pre>Deficient: 4953
Abundant: 15043
Perfect: 4</pre>
 
=={{header|VBScript}}==
<lang VBScript>Deficient = 0
Anonymous user