aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/fun
diff options
context:
space:
mode:
authorMarvin Borner2023-06-03 00:10:52 +0200
committerMarvin Borner2023-06-03 00:10:52 +0200
commit57732d780a44f401bf6551589b42269e0eb64448 (patch)
tree61e73aa097886c26e03ad02d2f6dfbbb2f332544 /samples/fun
parent869b979abca7fd4f96a9ed5a1158a8e5af92c1f1 (diff)
Added collatz conjecture
Diffstat (limited to 'samples/fun')
-rw-r--r--samples/fun/collatz.bruijn16
1 files changed, 16 insertions, 0 deletions
diff --git a/samples/fun/collatz.bruijn b/samples/fun/collatz.bruijn
new file mode 100644
index 0000000..c6b6057
--- /dev/null
+++ b/samples/fun/collatz.bruijn
@@ -0,0 +1,16 @@
+# bruijn collatz.bruijn
+# fun collatz implementation using binary abstract machine
+
+:import std/Combinator .
+:import std/Number/Binary .
+
+# TODO: add String → Binary function for reading from stdin
+start (+01189998819991197253b)
+
+collatz [z [[rec]] (=²?0 ≠²!(/²0) 0)] ⧗ Binary → Boolean
+ ≠²!‣ z [[=²?0 (1 /²0) 0]]
+ rec (0 =? (+1b)) case-end case-rec
+ case-rec 1 ≠²!(↑¹0 + 0)
+ case-end [[1]]
+
+main [collatz start]