From ca3907431bfde5aa0715945222ce777d72e6b411 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 2 Mar 2024 16:16:51 +0100 Subject: Docs & samples --- samples/rosetta/hailstone.bruijn | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 samples/rosetta/hailstone.bruijn (limited to 'samples/rosetta/hailstone.bruijn') diff --git a/samples/rosetta/hailstone.bruijn b/samples/rosetta/hailstone.bruijn new file mode 100644 index 0000000..46cf8a2 --- /dev/null +++ b/samples/rosetta/hailstone.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 (+1000) (iterate ++‣ (+1b)) + +main [head (max-by (M.compare ⋔ tail) all-below-100000)] -- cgit v1.2.3