From f951d315416b67b5929f78a9cd42ed54c6dd132c Mon Sep 17 00:00:00 2001 From: dedesaepulloh Date: Sun, 10 Oct 2021 13:58:40 +0700 Subject: [PATCH] add fibonacci --- KOTLIN/fibonacci.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 KOTLIN/fibonacci.kt diff --git a/KOTLIN/fibonacci.kt b/KOTLIN/fibonacci.kt new file mode 100644 index 00000000..66a260fa --- /dev/null +++ b/KOTLIN/fibonacci.kt @@ -0,0 +1,11 @@ +fun main() { + println(fibonacci().take(10).toList()) +} + +fun fibonacci() = sequence { + var terms = Pair(0, 1) + while (true) { + yield(terms.first) + terms = Pair(terms.second, terms.first + terms.second) + } +} \ No newline at end of file