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.



class NthRoot {
  function : Main(args : String[]) ~ Nil {
    NthRoot(5, 34, .001)->PrintLine();
  }
 
  function : NthRoot(n : Int, A: Float, p : Float) ~ Float {
    x := Float->New[2];
    x[0] := A;
    x[1] := A / n;
 
    while((x[1] - x[0])->Abs() > p) {
      x[0] := x[1];
      x[1] := ((n - 1.0) * x[1] + A / x[1]->Power(n - 1.0)) / n;
    };
 
    return x[1];
  }
}