Last active
July 2, 2018 08:53
-
-
Save lpeppe/38d96e2b407893808473e90db95b3cc6 to your computer and use it in GitHub Desktop.
Fibonacci implementation in scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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