tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
11
Task/Nth-root/Perl-6/nth-root.pl6
Normal file
11
Task/Nth-root/Perl-6/nth-root.pl6
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
sub nth-root ($n, $A, $p=1e-9)
|
||||
{
|
||||
my $x0 = $A / $n;
|
||||
loop {
|
||||
my $x1 = (($n-1) * $x0 + $A / ($x0 ** ($n-1))) / $n;
|
||||
return $x1 if abs($x1-$x0) < abs($x0 * $p);
|
||||
$x0 = $x1;
|
||||
}
|
||||
}
|
||||
|
||||
say nth-root(3,8);
|
||||
Loading…
Add table
Add a link
Reference in a new issue