RosettaCodeData/Task/Perfect-numbers/D/perfect-numbers-1.d

13 lines
257 B
D
Raw Permalink Normal View History

2014-04-02 16:56:35 +00:00
import std.stdio, std.algorithm, std.range;
2013-04-10 23:57:08 -07:00
2014-04-02 16:56:35 +00:00
bool isPerfectNumber1(in uint n) pure nothrow
in {
assert(n > 0);
} body {
return n == iota(1, n - 1).filter!(i => n % i == 0).sum;
2013-04-10 23:57:08 -07:00
}
void main() {
2014-04-02 16:56:35 +00:00
iota(1, 10_000).filter!isPerfectNumber1.writeln;
2013-04-10 23:57:08 -07:00
}