diff --git a/Language/Kotlin/FibonacciOnCorutine.kt b/Language/Kotlin/FibonacciOnCorutine.kt new file mode 100644 index 00000000..c365f297 --- /dev/null +++ b/Language/Kotlin/FibonacciOnCorutine.kt @@ -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) { + val limit = args.elementAtOrNull(1)?.toIntOrNull() ?: 100_000 + println(fibonacci.take(limit).last()) +} +