Skip to content

Instantly share code, notes, and snippets.

@cesartl
Last active May 17, 2020 13:47
Show Gist options
  • Save cesartl/746f8e116051048bf82812dec39e8ac6 to your computer and use it in GitHub Desktop.
Save cesartl/746f8e116051048bf82812dec39e8ac6 to your computer and use it in GitHub Desktop.
Basic Fibonacci Implementation
fun fibonacciSlow(n: BigInteger) = when {
n <= BigInteger.ONE -> n
else -> fibonacciSlow(n - BigInteger.ONE) + fibonacciSlow(n - BigInteger.TWO)
}
@CLOVIS-AI
Copy link

I think it would be better to write it this way:

fun fibonacciSlow(n: BigInteger) = when {
  n <= BigInteger.ONE -> n
  else -> fibonacciSlow(n - BigInteger.ONE) + fibonacciSlow(n - BigInteger.TWO)
}

I think it's better to take full advantage of the capabilities and syntax of the language for your demonstrations ^^

@cesartl
Copy link
Author

cesartl commented May 17, 2020

Sure good idea, I'll update it 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment