Abundant, deficient and perfect number classifications: Difference between revisions
Content added Content deleted
Line 374: | Line 374: | ||
<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 classifier(i: Int) = properDivisors(i).sum compare i |
def classifier(i: Int) = properDivisors(i).sum compare i |
||
val groupNames = Vector("Deficient", "Perfect", "Abundant") |
|||
val groups = (1 to 20000).groupBy( classifier ) |
val groups = (1 to 20000).groupBy( classifier ) |
||
println("Deficient: " + groups(-1).length) |
|||
println("Abundant: " + groups(1).length) |
|||
println("Perfect: " + groups(0).length + " (" + groups(0).mkString(",") + ")")</lang> |
|||
{{out}} |
{{out}} |
||
<pre>Deficient: 15043 |
<pre>Deficient: 15043 |
||
Abundant: 4953 |
Abundant: 4953 |
||
Perfect: 4</pre> |
Perfect: 4 (6,28,496,8128)</pre> |
||
=={{header|VBScript}}== |
=={{header|VBScript}}== |