Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
object Main extends App {
// your code goes here
def fib(n: Int): Int = {
@annotation.tailrec
def loop(count: Int, pp: Int, p: Int): Int = {
// println(s"n: $n, count: $count, pp: $pp, p: $p")
if(count < n - 2) {
loop(count + 1, p, p + pp)
} else {
pp + p
}
}
loop(0, 0, 1)
}
println(fib(8))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.