Created
March 16, 2020 18:59
-
-
Save Hoobie/a94f080bb00279c13b9ecf42a12f8248 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(n: Int): Int = | |
if (n == 0) 0 | |
else if (n == 1) 1 | |
else fibonacci(n - 1) + fibonacci(n - 2) | |
@scala.annotation.tailrec | |
def tailFibonacci(n: Int, prev: Int = 0, acc: Int = 1): Int = | |
if (n == 0) prev | |
else if (n == 1) acc | |
else tailFibonacci(n - 1, acc, acc + prev) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment