aboutsummaryrefslogtreecommitdiff
path: root/challenge-055/richard-park/apl/WaveArray.aplf
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
     p0 99Pmat n        ⍝ Permutations of ⍵
     gte(¯1+n)1 0          ⍝ Wave-array greater-than or equal pattern
     lte~gte                ⍝ Wave-array less-than or equal pattern
     ggte12/(⍋⍋)¯1p   ⍝ Permutations with wave gte pattern
     llte12/(⍋⍋)¯1p   ⍝ Permutations with wave lte pattern
     (gl)p                ⍝ Unique wave permutations of ⍵
 }