tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
16
Task/Nth-root/Scala/nth-root.scala
Normal file
16
Task/Nth-root/Scala/nth-root.scala
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
object NthRoot {
|
||||
|
||||
def main(args: Array[String]) {
|
||||
println(nthroot(3, 32))
|
||||
}
|
||||
|
||||
def nthroot1(n: Int, a: Double): Double = {
|
||||
def loop(x0: Double) : Double = {
|
||||
val x1 = (1.0d/n * ((n - 1) * x0 + a/math.pow(x0, n-1)))
|
||||
if (x0 <= x1) x0
|
||||
else loop(x1)
|
||||
}
|
||||
|
||||
return loop(a/2)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue