From 57732d780a44f401bf6551589b42269e0eb64448 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 3 Jun 2023 00:10:52 +0200 Subject: Added collatz conjecture --- samples/fun/collatz.bruijn | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 samples/fun/collatz.bruijn (limited to 'samples/fun/collatz.bruijn') 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] -- cgit v1.2.3