diff options
Diffstat (limited to 'samples/rosetta/hailstone_sequence.bruijn')
-rw-r--r-- | samples/rosetta/hailstone_sequence.bruijn | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/samples/rosetta/hailstone_sequence.bruijn b/samples/rosetta/hailstone_sequence.bruijn new file mode 100644 index 0000000..d98c235 --- /dev/null +++ b/samples/rosetta/hailstone_sequence.bruijn @@ -0,0 +1,21 @@ +: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)] |