Task

Implement the algorithm to compute the principal   nth   root   





A

n





{\displaystyle {\sqrt[{n}]{A}}}

   of a positive real number   A,   as explained at the   Wikipedia page.



func nthroot(n, a, precision=1e-5) {
  var x    = 1.float
  var prev = 0.float
  while ((prev-x).abs > precision) {
    prev = x;
    x = (((n-1)*prev + a/(prev**(n-1))) / n)
  }
  return x
}
 
say nthroot(5, 34)  # => 2.024397458501034082599817835297912829678314204