Skip to content

Instantly share code, notes, and snippets.

@inanna-malick
Created May 7, 2015 17:55
Show Gist options
  • Save inanna-malick/7352d88155bc35add75d to your computer and use it in GitHub Desktop.
Save inanna-malick/7352d88155bc35add75d to your computer and use it in GitHub Desktop.
fibonacci
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