tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,21 @@
import std.stdio, std.math, std.range, std.algorithm;
bool isPerfectNumber(in int n) pure nothrow {
if (n < 2)
return false;
int sum = 1;
foreach (i; 2 .. cast(int)sqrt(cast(real)n) + 1)
if (n % i == 0) {
immutable int q = n / i;
sum += i;
if (q > i)
sum += q;
}
return sum == n;
}
void main() {
iota(10_000).filter!isPerfectNumber().writeln();
}

View file

@ -0,0 +1,9 @@
import std.stdio, std.algorithm, std.range;
bool isPerfect(in int n) /*pure nothrow*/ {
return n == iota(1, n - 1).reduce!((s, i) => n % i ? s : s + i)();
}
void main() {
iota(3, 10_000).filter!isPerfect().writeln();
}