diff options
author | Marvin Borner | 2024-03-03 15:03:41 +0100 |
---|---|---|
committer | Marvin Borner | 2024-03-03 22:29:24 +0100 |
commit | 6ae44d09faa0ae353c0818705503cad42127d102 (patch) | |
tree | a923d00d520f85a608f51416184e5b3b6f178549 /samples/rosetta/fibonacci_sequence.bruijn | |
parent | 03155d6e515c76d5ab59f814592484c849313130 (diff) |
Even more samples
wtf
Diffstat (limited to 'samples/rosetta/fibonacci_sequence.bruijn')
-rw-r--r-- | samples/rosetta/fibonacci_sequence.bruijn | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/samples/rosetta/fibonacci_sequence.bruijn b/samples/rosetta/fibonacci_sequence.bruijn new file mode 100644 index 0000000..d2e4752 --- /dev/null +++ b/samples/rosetta/fibonacci_sequence.bruijn @@ -0,0 +1,20 @@ +:import std/Combinator . +:import std/Math . +:import std/List . + +# unary/Church fibonacci (moderately fast but very high space complexity) +fib-unary [0 [[[2 0 [2 (1 0)]]]] k i] + +:test (fib-unary (+6u)) ((+8u)) + +# ternary fibonacci using infinite list iteration (very fast) +fib-list \index fibs + fibs head <$> (iterate &[[0 : (1 + 0)]] ((+0) : (+1))) + +:test (fib-list (+6)) ((+8)) + +# recursive fib (very slow) +fib-rec y [[0 <? (+1) (+0) (0 <? (+2) (+1) rec)]] + rec (1 --0) + (1 --(--0)) + +:test (fib-rec (+6)) ((+8)) |