Skip to content

Instantly share code, notes, and snippets.

@riccardomerolla
Last active September 8, 2022 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riccardomerolla/31e959db3e01e8326b41e4094f75e074 to your computer and use it in GitHub Desktop.
Save riccardomerolla/31e959db3e01e8326b41e4094f75e074 to your computer and use it in GitHub Desktop.
Fibonacci
def fibonacci(num: Int): BigInt =
@scala.annotation.tailrec
def fibFcn(n: Int, acc1: BigInt, acc2: BigInt): BigInt = n match
case 0 => acc1
case 1 => acc2
case _ => fibFcn(n - 1, acc2, acc1 + acc2)
fibFcn(num, 0, 1)
fibonacci(90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment