diff options
author | Marvin Borner | 2024-03-02 16:16:51 +0100 |
---|---|---|
committer | Marvin Borner | 2024-03-02 19:30:59 +0100 |
commit | ca3907431bfde5aa0715945222ce777d72e6b411 (patch) | |
tree | 5399b72899c5d66f94782892ba9dbf29839aca22 /samples/rosetta/hailstone.bruijn | |
parent | 46cc8f5b0da07d8c7cb354c7b7a281b8d0f3d7bf (diff) |
Docs & samples
Diffstat (limited to 'samples/rosetta/hailstone.bruijn')
-rw-r--r-- | samples/rosetta/hailstone.bruijn | 21 |
1 files changed, 21 insertions, 0 deletions
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)] |