Created
May 8, 2021 08:39
-
-
Save CheolhoJeon/fe5c5ffccefb7e931ba107c68e0f77ee to your computer and use it in GitHub Desktop.
This file contains 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
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