rosetta/hailstone_sequence.bruijn

Problem description

:import std/Combinator .
:import std/List .
:import std/Math M
:import std/Number/Binary .

# hailstone sequence using binary shifts
hailstone y [[(0 =? (+1b)) {}0 go]]
	go 0 : (=²?0 (1 /²0) (1 (↑¹0 + 0)))

# --- tests ---

seq-27 hailstone (+27b)

:test (∀seq-27) ((+112))
:test (take (+4) seq-27) ((+27b) : ((+82b) : ((+41b) : {}(+124b))))
:test (take (+4) <~>seq-27) ((+1b) : ((+2b) : ((+4b) : {}(+8b))))

all-below-100000 [0 : ∀(hailstone 0)] <$> seq
	seq take (+99999) (iterate ++‣ (+1b))

main [head (max-by (M.compare ⋔ tail) all-below-100000)]