Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fibonacci in Kotlin
package tm.alashow.homework.datastructures.second.kt import java.math.BigInteger fun main(args: Array<String>) { Fibonacci.init() } object Fibonacci { fun init() { val n = 300L // seed is 0 and 1 fibonacci(BigInteger.ZERO, BigInteger.ONE, BigInteger.valueOf(n)) } /** * Calculates and prints each step of Fibonacci using tail recursion. * * tailrec modifier used to use tail recursion optimization. */ tailrec private fun fibonacci(a: BigInteger, b: BigInteger, n: BigInteger): BigInteger { print("$a, ") return if (n == BigInteger.ZERO) a else fibonacci(b, a + b, n - BigInteger.ONE) } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Aula 1 - Orientacao a Objetos - Mao na Massa
Calendar 2018 v3.2 (Compressed Coding)
dfg
Haha
Arun1
?. in Kotlin
validation testing
test.java
degerliilkornek
Function Call, Arithmetic Operations, User Input and more in Kotlin
Please log in to post a comment.