Integer roots: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) 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); |
|||
10**($n.chars div $p), |
|||
{ ( $d * $^x + $n div ($x ** $d) ) div $p } ... |
|||
{ $_**$p ≤ $n < ($_+1)**$p } |
|||
).tail |
|||
min (+$guess, $iterator ... $endpoint)[*-1, *-2]; |
|||
} |
} |
||