Created
October 31, 2014 19:19
-
-
Save takscape/957ca588251bf1f64c77 to your computer and use it in GitHub Desktop.
Fibonacci Sequence in Kotlin
This file contains hidden or 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
import java.math.BigInteger | |
import kotlin.math.plus | |
fun main(args: Array<String>) { | |
fibo().take(10).forEach { println(it) } | |
} | |
private fun fibo() : FunctionStream<BigInteger> { | |
var cur = BigInteger.ZERO | |
var next = BigInteger.ONE | |
return FunctionStream({() -> | |
val ret = cur | |
cur = next | |
next = next plus ret | |
ret | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment