Advertisement
Guest User

Untitled

a guest
Feb 26th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.23 KB | None | 0 0
  1.   {
  2.     def f(x: Double, n: Int): Double = {
  3.       if (n == 0) 1
  4.       else if (n > 0 && n % 2 == 0) f(f(x, n/2), 2)
  5.       else if (n > 0 && n % 2 != 0) x * f(x, n - 1)
  6.       else (1 / f(x, -n))
  7.     }
  8.     println(f(4,3))
  9.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement