fork download
  1. object Main extends App {
  2. // your code goes here
  3. def fib(n: Int): Int = {
  4. if (n == 1) 0
  5. else if (n == 2) 1
  6. else {
  7. def go(x1: Int, x2: Int, n: Int): Int = if (n == 0) x2 else go(x2, x1 + x2, n-1)
  8. go(0, 1, n-2)
  9. }
  10. }
  11. println(fib(3))
  12. }
Success #stdin #stdout 0.39s 382016KB
stdin
Standard input is empty
stdout
1