Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Resolve #3. Add Fibonacci algorithm #95

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Language/Kotlin/FibonacciOnCorutine.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
val fibonacci = sequence {
var current = BigDecimal(1)
var next = BigDecimal(1)
yield(current)
while (true) {
yield(next)
val tmp = current + next
current = next
next = tmp
}
}

fun main(args: Array<String>) {
val limit = args.elementAtOrNull(1)?.toIntOrNull() ?: 100_000
println(fibonacci.take(limit).last())
}