Skip to content

Instantly share code, notes, and snippets.

@cbruegg
Created February 2, 2019 13:16
Show Gist options
  • Save cbruegg/2bb1a66c6aa6e53a5c5dfc4320b1c4f7 to your computer and use it in GitHub Desktop.
Save cbruegg/2bb1a66c6aa6e53a5c5dfc4320b1c4f7 to your computer and use it in GitHub Desktop.
fun main(args: Array<String>) {
println(fib().take(5).toList())
}
fun fib() = sequence<Int> {
yield(1)
yield(1)
var prev = 1
var prevPrev = 1
while (true) {
val cur = prevPrev + prev
yield(cur)
prevPrev = prev
prev = cur
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment