Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2012
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.38 KB | None | 0 0
  1. package tail
  2. import scala.annotation.tailrec
  3. import scala.math.BigInt
  4.  
  5. final object Fibonacci {
  6.     def fibonacci(n : Int) : BigInt = {
  7.         @tailrec
  8.         def fib_sum(n : Int, part_sum : BigInt, sum : BigInt) : BigInt = n match {
  9.             case 0 | 1 => part_sum
  10.             case _ => fib_sum(n - 1, part_sum + sum, part_sum)
  11.         }
  12.         fib_sum(n, 1, 1)
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement