diff options
Diffstat (limited to 'examples/fifty.bqn')
| -rw-r--r-- | examples/fifty.bqn | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/fifty.bqn b/examples/fifty.bqn index cc452ce4..34222304 100644 --- a/examples/fifty.bqn +++ b/examples/fifty.bqn @@ -93,6 +93,47 @@ SeventeenTwentyNine ← {F: } # ! 1729 ≡ SeventeenTwentyNine⟨⟩ # slow +# 19 +Permutations ← {𝕊0:1‿0⥊0; ∾<˘(0∾˘1+𝕊𝕩-1)⊏⎉2‿1⍒˘=⌜˜↕𝕩} +! (6‿3⥊0‿1‿2‿0‿2‿1‿1‿0‿2‿1‿2‿0‿2‿0‿1‿2‿1‿0)≡Permutations 3 + +# 20 +InversePermutation ← ⍋ #Alternatively: ⊐⟜(↕≠) +! (↕10)≡InversePermutation⊸⊏1‿4‿5‿2‿6‿8‿3‿7‿0‿9 + +# 21 +IndexFromPermutation‿PermutationFromIndex ← { + Rfd ← ⊢+´∘>¨¯1↓↓ + Dfr ← (⍋∘⍋∾)´ + Ifp ← {⌽×`1+»↕≠𝕩} +´∘× Rfd + Pfi ← Dfr (1+↕)⊸(⌽⊣|¯1↓·⌊∘÷`∾˜) + Ifp‿Pfi +} +! { + p ← 1‿3‿0‿7‿6‿5‿4‿9‿8‿2 + p ≡ 10 PermutationFromIndex IndexFromPermutation p +} + +# 22 +Combinations ← {𝕨(=∨0=⊣)◶⟨(0∾˘𝕊⌾(-⟜1))∾1+𝕊⟜(-⟜1), ≍∘↕⊣⟩𝕩} +! (3 Combinations 5) ≡ 10‿3⥊0‿1‿2‿0‿1‿3‿0‿1‿4‿0‿2‿3‿0‿2‿4‿0‿3‿4‿1‿2‿3‿1‿2‿4‿1‿3‿4‿2‿3‿4 + +# 23 +IndexFromCombination‿CombinationFromIndex ← { + C ← ((-˜+↕∘⊣)÷○(×´1⊸+)↕∘⊣)˘ + Ic ← {m‿n←𝕨 ⋄ ⊑-˝(m-↕m) +˝∘(C˘) n-(»1+𝕩)∾˘𝕩} + Ci ← { + 0‿i𝕊𝕩: ⟨⟩; + m‿n←𝕨 + v←⥊+`(m-1)C(1-m)↓⌽↕n + k←(v>𝕩)⊐1 + k∾(1+k)+(𝕨-1∾1+k)𝕊(𝕩-k⊏0∾v) + } + Ic‿Ci +} +! 11 ≡ 4‿6 IndexFromCombination 1‿2‿3‿5 +! 1‿2‿3‿5 ≡ 4‿6 CombinationFromIndex 11 + # 24 SymmetricArray ← ⍉⊸≡ ∧ 1⊸⍉⊸≡ ! SymmetricArray +⌜´ 3⥊<2‿3‿7‿11 |
