Anonymous user
Abundant, deficient and perfect number classifications: Difference between revisions
Abundant, deficient and perfect number classifications (view source)
Revision as of 18:46, 10 February 2015
, 9 years ago→{{header|Scala}}
Line 374:
<lang Scala>def properDivisors(n: Int) = (1 to n/2).filter(i => n % i == 0)
def classifier(i: Int) = properDivisors(i).sum compare i
val groups = (1 to 20000).groupBy( classifier )
println("Abundant: " + groups(1).length)
println("Perfect: " + groups(0).length + " (" + groups(0).mkString(",") + ")")</lang>
{{out}}
<pre>Deficient: 15043
Abundant: 4953
Perfect: 4 (6,28,496,8128)</pre>
=={{header|VBScript}}==
|