aboutsummaryrefslogtreecommitdiff
path: root/fib.kpl
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-08-21 09:54:00 -0400
committernodist <kevin.comas.git@gmail.com>2026-08-21 09:54:00 -0400
commite8434234f2dc7ef89477205aae05cabc4ac41d39 (patch)
tree5569e757cb352eee453536cb6f985e3c0bb42b31 /fib.kpl
parentb5111570d2de58741d2d932cb149dfe5aea39d1b (diff)
new examples
Diffstat (limited to 'fib.kpl')
-rw-r--r--fib.kpl38
1 files changed, 38 insertions, 0 deletions
diff --git a/fib.kpl b/fib.kpl
new file mode 100644
index 0000000..1ce17e6
--- /dev/null
+++ b/fib.kpl
@@ -0,0 +1,38 @@
+
+// Fibonacci Example
+
+fib_recursive : `{[I64 n]
+ ? n < 0 { .error $ "n Cannot Be Negative" }
+ fib : `{[I64 n]
+ ? {
+ n = 0 { 0 }
+ n < 2 { 1 }
+ { + (fib `sync n - 1; fib `sync n - 2) }
+ }
+ }
+ fib `sync n
+}
+
+fib_loop : `{[I64 n]
+ ? n < 0 { `return.error $ "n Cannot Be Negative" }
+ a : 0
+ b : 1
+ @ 0 .. n {
+ c : b
+ b +: a
+ a : c
+ }
+ a
+}
+
+fib_array : `{[I64 n]
+ ? {
+ n < 0 { `return.error $ "n Cannot Be Negative" }
+ n > 1 { n -: 1 }
+ }
+ arr : Array (0; 1)
+ @ 0 .. n {
+ arr `push arr[-2] + arr[-1]
+ }
+ arr
+}