Skip to content

Instantly share code, notes, and snippets.

@pkinsky pkinsky/fib.scala
Created May 7, 2015

What would you like to do?
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
You can’t perform that action at this time.