Jump to content

Integer roots: Difference between revisions

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

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.