Skip to content

Instantly share code, notes, and snippets.

@FScoward
Created March 23, 2015 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FScoward/bde2ea08247d5ccb12a9 to your computer and use it in GitHub Desktop.
Save FScoward/bde2ea08247d5ccb12a9 to your computer and use it in GitHub Desktop.
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