aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/fifty.bqn14
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)
}