Skip to content

Instantly share code, notes, and snippets.

@CheolhoJeon
Created May 8, 2021 08:39
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 CheolhoJeon/fe5c5ffccefb7e931ba107c68e0f77ee to your computer and use it in GitHub Desktop.
Save CheolhoJeon/fe5c5ffccefb7e931ba107c68e0f77ee to your computer and use it in GitHub Desktop.
package chap4.Recursion
import atomictest.eq
fun fibonacci(n: Long): Long {
return when (n) {
0L -> 0
1L -> 1
else ->
fibonacci(n - 1) + fibonacci(n - 2)
}
}
fun main() {
fibonacci(0) eq 0
fibonacci(22) eq 17711
// Very time-consuming:
// fibonacci(50) eq 12586269025
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment