aboutsummaryrefslogtreecommitdiff
path: root/challenge-057/richard-park/apl/ch-2.aplf
blob: e4d2f0c9841a9bcf2f1c67f9942c8407a51b0836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 ShortestUniquePrefix{
⍝ ⍵: Nested list of words 
⍝ ←: Shortest unique prefixes, not in order
     I((⊃⊣)⌷⊢)0 99            ⍝ Select indexer
     1                        ⍝ Prefix length     
     p¨                    ⍝ Prefixes
     (u c i)↓⍉{()()()}p   ⍝ (Unique Count Indices)
     umc=1                     ⍝ Unique prefix mask
     0=⍴⍵:                     ⍝ All SUPs found: Return empty array
     0=∨/um:(+1)             ⍝ No unique prefixes: 
                                ⍝   increment prefix length
                                ⍝     ∇ recurse
     cwii⌿⍨um                  ⍝ Completed word indices
     cw Icwi                 ⍝ Completed words
     upu⌿⍨um                   ⍝ Unique prefixes
                                ⍝ Unique prefixes found: 
                                ⍝   Return unique prefixes,
                                ⍝     increment prefix length
                                ⍝       ∇ recurse with remaining words
     um:(¨up),(+1) ~cw 
 }