Perfect numbers: Difference between revisions
Content deleted Content added
Updated both D entries |
|||
Line 366: | Line 366: | ||
void main() { |
void main() { |
||
iota(10_000).filter!isPerfectNumber().writeln(); |
|||
}</lang> |
}</lang> |
||
{{out}} |
|||
Output: |
|||
⚫ | |||
With a iota(33_550_337) it outputs: |
|||
<pre>[6, 28, 496, 8128, 33550336]</pre> |
<pre>[6, 28, 496, 8128, 33550336]</pre> |
||
===Functional Style=== |
===Functional Style=== |
||
Same output. |
|||
<lang d>import std.stdio, std.algorithm, std.range; |
<lang d>import std.stdio, std.algorithm, std.range; |
||
bool isPerfect(in int n) { |
bool isPerfect(in int n) /*pure nothrow*/ { |
||
return n == reduce!((s, i) => n % i ? s : s+i)( |
return n == iota(1, n - 1).reduce!((s, i) => n % i ? s : s + i)(); |
||
} |
} |
||
void main() { |
void main() { |
||
iota(3, 10_000).filter!isPerfect().writeln(); |
|||
}</lang> |
}</lang> |
||
Output: |
|||
⚫ | |||
=={{header|E}}== |
=={{header|E}}== |