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

Commit

Permalink
Merge pull request #95 from Melancholic/master
Browse files Browse the repository at this point in the history
Resolve #3. Add Fibonacci algorithm
  • Loading branch information
Harshsngh07 committed Oct 24, 2019
2 parents e277ebf + cb9f064 commit 2fa9cc4
Showing 1 changed file with 17 additions and 0 deletions.
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())
}

0 comments on commit 2fa9cc4

Please sign in to comment.