From 9549fd1f14fef5b799f795d91f391df7d4c4826a Mon Sep 17 00:00:00 2001 From: j-james Date: Sat, 29 Oct 2022 18:56:59 -0700 Subject: Add Nim --- entries/jj/nim/fib.nim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 entries/jj/nim/fib.nim (limited to 'entries') diff --git a/entries/jj/nim/fib.nim b/entries/jj/nim/fib.nim new file mode 100644 index 0000000..a12f8e6 --- /dev/null +++ b/entries/jj/nim/fib.nim @@ -0,0 +1,17 @@ +func fib(n: Natural): Natural = + if n < 2: + return n + else: + return fib(n-1) + fib(n-2) + +func fib2(n: int, a = 0, b = 1): int = + return if n == 0: a else: fib2(n-1, b, a+b) + +iterator fib3: int = + var a = 0 + var b = 1 + while true: + yield a + swap a, b + b += a + -- cgit v1.2.3-70-g09d2