Skip to content

Instantly share code, notes, and snippets.

@lpeppe
Last active July 2, 2018 08:53
Show Gist options
  • Save lpeppe/38d96e2b407893808473e90db95b3cc6 to your computer and use it in GitHub Desktop.
Save lpeppe/38d96e2b407893808473e90db95b3cc6 to your computer and use it in GitHub Desktop.
Fibonacci implementation in scala
def fib(n: Int): Int = {
def go(n: Int, prev: Int, curr: Int): Int = {
if(n == 0) prev
else go(n - 1, curr, prev + curr)
}
go(n, 0, 1)
}
fib(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment