Skip to content

Instantly share code, notes, and snippets.

@takscape
Created October 31, 2014 19:19
Show Gist options
  • Save takscape/957ca588251bf1f64c77 to your computer and use it in GitHub Desktop.
Save takscape/957ca588251bf1f64c77 to your computer and use it in GitHub Desktop.
Fibonacci Sequence in Kotlin
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