diff options
| author | nodist <kevin.comas.git@gmail.com> | 2026-08-21 09:54:00 -0400 |
|---|---|---|
| committer | nodist <kevin.comas.git@gmail.com> | 2026-08-21 09:54:00 -0400 |
| commit | e8434234f2dc7ef89477205aae05cabc4ac41d39 (patch) | |
| tree | 5569e757cb352eee453536cb6f985e3c0bb42b31 /fib.kpl | |
| parent | b5111570d2de58741d2d932cb149dfe5aea39d1b (diff) | |
new examples
Diffstat (limited to 'fib.kpl')
| -rw-r--r-- | fib.kpl | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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 +} |
