Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tail
- import scala.annotation.tailrec
- import scala.math.BigInt
- final object Fibonacci {
- def fibonacci(n : Int) : BigInt = {
- @tailrec
- def fib_sum(n : Int, part_sum : BigInt, sum : BigInt) : BigInt = n match {
- case 0 | 1 => part_sum
- case _ => fib_sum(n - 1, part_sum + sum, part_sum)
- }
- fib_sum(n, 1, 1)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement