Created
May 7, 2015 17:55
-
-
Save inanna-malick/7352d88155bc35add75d to your computer and use it in GitHub Desktop.
fibonacci
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 fibonacci(number: Int): Int = { | |
assert(number >= 0) | |
@annotation.tailrec def inner(prev: Int, curr: Int, n: Int): Int = | |
if (n < number) inner(curr, prev + curr, n + 1) | |
else curr | |
if (number == 0) 0 | |
else if (number == 1) 1 | |
else inner(0, 1, 1) | |
} | |
println((0 to 10).map(fibonacci)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment