Integer roots: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
(→‎{{header|Raku}}: simplifying with the sequence operator)
Line 980: Line 980:
<syntaxhighlight lang="raku" line>sub integer_root ( Int $p where * >= 2, Int $n --> Int ) {
<syntaxhighlight lang="raku" line>sub integer_root ( Int $p where * >= 2, Int $n --> Int ) {
my Int $d = $p - 1;
my Int $d = $p - 1;
(
my $guess = 10**($n.chars div $p);
my $iterator = { ( $d * $^x + $n div ($^x ** $d) ) div $p };
10**($n.chars div $p),
my $endpoint = { $^x ** $p <= $n
{ ( $d * $^x + $n div ($x ** $d) ) div $p } ...
and ($^x + 1) ** $p > $n };
{ $_**$p $n < ($_+1)**$p }
).tail
min (+$guess, $iterator ... $endpoint)[*-1, *-2];
}
}