aboutsummaryrefslogtreecommitdiff
path: root/entries/omentic/nim
diff options
context:
space:
mode:
authorbraxtonhall2023-07-13 18:26:58 +0000
committerbraxtonhall2023-07-13 18:26:58 +0000
commitc37b806da507a699624ec4e800522ef4a47ad7bc (patch)
treebfe99e81e91603508be51bcd31f7bbb4d48f6b6f /entries/omentic/nim
parent972c5f34cd093d44e801bf6b41ac0af2032b0b96 (diff)
Update directories
Diffstat (limited to 'entries/omentic/nim')
-rw-r--r--entries/omentic/nim/fib.nim17
1 files changed, 17 insertions, 0 deletions
diff --git a/entries/omentic/nim/fib.nim b/entries/omentic/nim/fib.nim
new file mode 100644
index 0000000..a12f8e6
--- /dev/null
+++ b/entries/omentic/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
+