Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -1,12 +1,13 @@
|
|||
import std.stdio, std.typecons, std.conv, std.bigint;
|
||||
import std.stdio, std.typecons, std.conv, std.bigint, std.math,
|
||||
std.traits;
|
||||
|
||||
Tuple!(int, T) digitalRoot(T)(T root, in uint base) /*pure nothrow*/
|
||||
Tuple!(uint, Unqual!T) digitalRoot(T)(in T inRoot, in uint base)
|
||||
pure /*nothrow*/
|
||||
in {
|
||||
assert(base > 1);
|
||||
} body {
|
||||
if (root < 0)
|
||||
root = -root;
|
||||
int persistence = 0;
|
||||
Unqual!T root = inRoot.abs;
|
||||
uint persistence = 0;
|
||||
while (root >= base) {
|
||||
auto num = root;
|
||||
root = 0;
|
||||
|
|
@ -16,22 +17,20 @@ in {
|
|||
}
|
||||
persistence++;
|
||||
}
|
||||
return tuple(persistence, root);
|
||||
return typeof(return)(persistence, root);
|
||||
}
|
||||
|
||||
void main() {
|
||||
// import std.stdio, std.conv, std.bigint;
|
||||
enum f1 = "%s(%d): additive persistance= %d, digital root= %d";
|
||||
foreach (b; [2, 3, 8, 10, 16, 36]) {
|
||||
foreach (n; [5, 627615, 39390, 588225, 393900588225])
|
||||
writefln(f1, to!string(n,b), b, digitalRoot(n, b).tupleof);
|
||||
writeln();
|
||||
foreach (immutable b; [2, 3, 8, 10, 16, 36]) {
|
||||
foreach (immutable n; [5, 627615, 39390, 588225, 393900588225])
|
||||
writefln(f1, text(n, b), b, n.digitalRoot(b)[]);
|
||||
writeln;
|
||||
}
|
||||
|
||||
enum f2 = "<BIG>(%d): additive persistance= %d, digital root= %d";
|
||||
foreach (b; [2, 3, 8, 10, 16, 36]) {
|
||||
auto n = BigInt("58142718981673030403681039458302204471" ~
|
||||
"300738980834668522257090844071443085937");
|
||||
writefln(f2, b, digitalRoot(n, b).tupleof); // shortened output
|
||||
}
|
||||
immutable n = BigInt("581427189816730304036810394583022044713" ~
|
||||
"00738980834668522257090844071443085937");
|
||||
foreach (immutable b; [2, 3, 8, 10, 16, 36])
|
||||
writefln(f2, b, n.digitalRoot(b)[]); // Shortened output.
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue