Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Digital-root/Raku/digital-root-1.raku
Normal file
23
Task/Digital-root/Raku/digital-root-1.raku
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
sub digital-root ($r, :$base = 10) {
|
||||
my $root = $r.base($base);
|
||||
my $persistence = 0;
|
||||
while $root.chars > 1 {
|
||||
$root = $root.comb.map({:36($_)}).sum.base($base);
|
||||
$persistence++;
|
||||
}
|
||||
$root, $persistence;
|
||||
}
|
||||
|
||||
my @testnums =
|
||||
627615,
|
||||
39390,
|
||||
588225,
|
||||
393900588225,
|
||||
58142718981673030403681039458302204471300738980834668522257090844071443085937;
|
||||
|
||||
for 10, 8, 16, 36 -> $b {
|
||||
for @testnums -> $n {
|
||||
printf ":$b\<%s>\ndigital root %s, persistence %s\n\n",
|
||||
$n.base($b), digital-root $n, :base($b);
|
||||
}
|
||||
}
|
||||
6
Task/Digital-root/Raku/digital-root-2.raku
Normal file
6
Task/Digital-root/Raku/digital-root-2.raku
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
sub digital-root ($r, :$base = 10) {
|
||||
my &sum = { .comb.map({:36($_)}).sum.base($base) }
|
||||
|
||||
return .[*-1], .elems-1
|
||||
given $r.base($base), &sum … { .chars == 1 }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue