aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/fun/collatz.bruijn
blob: c6b60576eb96233e2e438e0b0fd1400bc7499bb6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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]