Run Code
|
API
|
Code Wall
|
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
GenerateFibonacci47
dfg
Haha
Kotlin
My script1
Aula 1 - Orientacao a Objetos - Mao na Massa
Kotlin!
Arun1
test.java
degerliilkornek