Abundant, deficient and perfect number classifications: Difference between revisions

m
(Scala solution)
Line 373:
=={{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_2.sum compare( divisors._2.sum)_1
val groupNames = Vector("Deficient", "Perfect", "Abundant")
val divisors = (1 to 20000).map( i => (i, properDivisors(i)) )
Line 379:
groups.foreach( v => println(groupNames(v._1 + 1) + ": " + v._2.length) )</lang>
{{out}}
<pre>Deficient: 495315043
Abundant: 150434953
Perfect: 4</pre>
 
Anonymous user