blob: 06fdfa0dd93b6f25161f922b780c5231fdb769e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
WaveArray←{
⍝ Thanks to Total Array Ordering, an array ⍵ can be reordered so that its major cells, m, have the property
⍝ (1⌷⍵)≥(2⌷⍵)≤(3⌷⍵)≥(4⌷⍵)≤...
⍝ ⍵: Array
⍝ ←: Array of rank (1+≢⍴⍵) where each major cell is a wave permutation of ⍵
n←≢⍵
p←⍵⌷⍤0 99⍨Pmat n ⍝ Permutations of ⍵
gte←(¯1+n)⍴1 0 ⍝ Wave-array greater-than or equal pattern
lte←~gte ⍝ Wave-array less-than or equal pattern
g←gte≡⍤1⊢2≥/(⍋⍋)⍤¯1⊢p ⍝ Permutations with wave gte pattern
l←lte≡⍤1⊢2≤/(⍋⍋)⍤¯1⊢p ⍝ Permutations with wave lte pattern
∪(g∧l)⌿p ⍝ Unique wave permutations of ⍵
}
|