Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
|||
import std.stdio, std.algorithm, std.typecons, std.range, std.conv;
|
||||
|
||||
/// Multiplicative digital root.
|
||||
auto mdRoot(in int n) pure /*nothrow*/ {
|
||||
auto mdr = [n];
|
||||
while (mdr.back > 9)
|
||||
mdr ~= reduce!q{a * b}(1, mdr.back.text.map!(d => d - '0'));
|
||||
//mdr ~= mdr.back.text.map!(d => d - '0').mul;
|
||||
//mdr ~= mdr.back.reverseDigits.mul;
|
||||
return tuple(mdr.length - 1, mdr.back);
|
||||
}
|
||||
|
||||
void main() {
|
||||
"Number: (MP, MDR)\n====== =========".writeln;
|
||||
foreach (immutable n; [123321, 7739, 893, 899998])
|
||||
writefln("%6d: (%s, %s)", n, n.mdRoot[]);
|
||||
|
||||
auto table = (int[]).init.repeat.enumerate!int.take(10).assocArray;
|
||||
auto n = 0;
|
||||
while (table.byValue.map!walkLength.reduce!min < 5) {
|
||||
table[n.mdRoot[1]] ~= n;
|
||||
n++;
|
||||
}
|
||||
"\nMP: [n0..n4]\n== ========".writeln;
|
||||
foreach (const mp; table.byKey.array.sort())
|
||||
writefln("%2d: %s", mp, table[mp].take(5));
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
import std.stdio, std.algorithm, std.typecons, std.range;
|
||||
|
||||
uint digitsProduct(uint n) pure nothrow @nogc {
|
||||
typeof(return) result = !!n;
|
||||
while (n) {
|
||||
result *= n % 10;
|
||||
n /= 10;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Multiplicative digital root.
|
||||
Tuple!(size_t, uint) mdRoot(uint m) pure nothrow {
|
||||
auto mdr = m
|
||||
.recurrence!((a, n) => a[n - 1].digitsProduct)
|
||||
.until!q{ a <= 9 }(OpenRight.no).array;
|
||||
return tuple(mdr.length - 1, mdr.back);
|
||||
}
|
||||
|
||||
void main() {
|
||||
"Number: (MP, MDR)\n====== =========".writeln;
|
||||
foreach (immutable n; [123321, 7739, 893, 899998])
|
||||
writefln("%6d: (%s, %s)", n, n.mdRoot[]);
|
||||
|
||||
auto table = (int[]).init.repeat.enumerate!int.take(10).assocArray;
|
||||
auto n = 0;
|
||||
while (table.byValue.map!walkLength.reduce!min < 5) {
|
||||
table[n.mdRoot[1]] ~= n;
|
||||
n++;
|
||||
}
|
||||
"\nMP: [n0..n4]\n== ========".writeln;
|
||||
foreach (const mp; table.byKey.array.sort())
|
||||
writefln("%2d: %s", mp, table[mp].take(5));
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
import std.stdio, std.algorithm, std.range;
|
||||
|
||||
/// Multiplicative digital root.
|
||||
uint[2] mdRoot(in uint n) pure nothrow @nogc {
|
||||
uint mdr = n;
|
||||
uint count = 0;
|
||||
|
||||
while (mdr > 9) {
|
||||
uint m = mdr;
|
||||
uint digitsMul = !!m;
|
||||
while (m) {
|
||||
digitsMul *= m % 10;
|
||||
m /= 10;
|
||||
}
|
||||
mdr = digitsMul;
|
||||
count++;
|
||||
}
|
||||
|
||||
return [count, mdr];
|
||||
}
|
||||
|
||||
void main() {
|
||||
"Number: [MP, MDR]\n====== =========".writeln;
|
||||
foreach (immutable n; [123321, 7739, 893, 899998])
|
||||
writefln("%6d: %s", n, n.mdRoot);
|
||||
|
||||
auto table = (int[]).init.repeat.enumerate!int.take(10).assocArray;
|
||||
auto n = 0;
|
||||
while (table.byValue.map!walkLength.reduce!min < 5) {
|
||||
table[n.mdRoot[1]] ~= n;
|
||||
n++;
|
||||
}
|
||||
"\nMP: [n0..n4]\n== ========".writeln;
|
||||
foreach (const mp; table.byKey.array.sort())
|
||||
writefln("%2d: %s", mp, table[mp].take(5));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue