Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,9 @@
def nroot(n: Int, a: Double): Double = {
@tailrec
def rec(x0: Double) : Double = {
val x1 = ((n - 1) * x0 + a/math.pow(x0, n-1))/n
if (x0 <= x1) x0 else rec(x1)
}
rec(a)
}

View file

@ -0,0 +1,2 @@
def fallPrefix(itr: Iterator[Double]): Iterator[Double] = itr.sliding(2).dropWhile(p => p(0) > p(1)).map(_.head)
def nrootLazy(n: Int)(a: Double): Double = fallPrefix(Iterator.iterate(a){r => (((n - 1)*r) + (a/math.pow(r, n - 1)))/n}).next