diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-10-17 13:58:20 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-10-17 13:58:20 -0400 |
| commit | 2d381ac8c137d5fc3eb33213c1684c25d6d6e5de (patch) | |
| tree | a7305fd5ac40b2bb99cb0074feba0895aae06a91 | |
| parent | 54b5e531d3526e7054e5ddc765bf0bcc32e8e521 (diff) | |
Tweaks to fifty functions 19-23
| -rw-r--r-- | examples/fifty.bqn | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/examples/fifty.bqn b/examples/fifty.bqn index db5bb4a5..32deb633 100644 --- a/examples/fifty.bqn +++ b/examples/fifty.bqn @@ -94,12 +94,12 @@ 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 +Permutations ← {𝕊0:1‿0⥊0; ∾<˘(0∾˘1+𝕊𝕩-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 +InversePermutation ← ⍋ # Or ⊐⟜(↕≠) or ∾∘⊔ +! (↕10) ≡ InversePermutation⊸⊏ 1‿4‿5‿2‿6‿8‿3‿7‿0‿9 # 21 IndexFromPermutation‿PermutationFromIndex ← { @@ -120,12 +120,12 @@ Combinations ← {𝕨(=∨0=⊣)◶⟨(0∾˘𝕊⌾(-⟜1))∾1+𝕊⟜(-⟜1) # 23 IndexFromCombination‿CombinationFromIndex ← { - C ← ((-˜+↕∘⊣)÷○(×´1⊸+)↕∘⊣)˘ + C ← ((-˜+↕∘⊣)÷○(×´1⊸+)↕∘⊣)˘ # Combination function (APL's dyadic !) Ic ← {m‿n←𝕨 ⋄ ⊑-˝(m-↕m) +˝∘(C˘) n-(»1+𝕩)∾˘𝕩} Ci ← { - 0‿i𝕊𝕩: ⟨⟩; + 0‿n𝕊𝕩: ⟨⟩; m‿n←𝕨 - v←⥊+`(m-1)C(1-m)↓⌽↕n + v←+`(m-1)C(1-m)↓⌽↕n k←(v>𝕩)⊐1 k∾(1+k)+(𝕨-1∾1+k)𝕊(𝕩-k⊏0∾v) } |
