Apl2ToDoManipulatingNumbersAlgorithms
This is a sub-page of PhraseBook/ToDo/Apl2Idioms
B←<\B ⍝ All zeros except the first one.
B←≤\B ⍝ All ones after the first zero.
B←∨\B ⍝ All ones after the first one.
B←^\B ⍝ All ones to the first zero.
B←+/^\B ⍝ Count of leading ones.
B←B∨≠\B ⍝ Parity+connectors. Connect odd & even ones.
B←≠\B ⍝ Parity. Connect odd and even ones.
B←2≠/0,B ⍝ Gray code or reflected binary. Inverse of ≠\.
B←2</0,B ⍝ Boolean first ones in each group of ones.
B←2>/B,0 ⍝ Boolean last ones in each group of ones.
B←1⌽B ⍝ Boolean start vector to boolean end vector.
B←I/(⍴I)⍴1 0 ⍝ Alternating sequence of I ones and zeros.
B←IS/L⍴1 0 ⍝ L sequences of IS ones and zeros.
L←¯2-/P,1+⍴B ⍝ Length vector given first position indices.
L←¯2-/0,P ⍝ Length vector given last position indices.
L←+/U∘.≡V ⍝ Length vector given unique items in V.
L←(1↓P,1+⍴B)-P←B/⍳⍴B ⍝ Length vector given boolean vector B.
NA←+/^\CA=' ' ⍝ Number of leading blanks.
NA←+/^\⌽CA=' ' ⍝ Number of trailing blanks.
N←+/¨(+\B)⊂N ⍝ Add subvectors of N given B breaks in group.
N←+/¨(L/1+⍳⍴L)⊂N ⍝ Add subvectors of N given L items per group.
N←+/¨(+\¯1↓1,G≠1⌽G)⊂N ⍝ Add subvectors of N from consecutive G dups.
N←+/¨(+\¯1↓1,∨/MG≠1⊖MG)⊂N ⍝ Add subvectors of N using ordered list MG.
N←N+.×V∘.≡U ⍝ Sum by bucket. ⍴N = ⍴V. U = buckets.
N←N×.*V∘.≡U ⍝ Product by bucket. ⍴N = ⍴V. U = buckets.
A←AX+.εY ⍝ Count of the number of Ys in each row of AX.
I←+\(C='(')-¯1↓0,C=')' ⍝ Depth of parenthesis.
VN←M,.⍳V ⍝ Position(s) of V in each row of M.
N←M⌊.⍳V ⍝ Position of V in corresponding row of M.
B←(<\'/*'⍷CA)∨⌽<\'/*'⍷⌽CA ⍝ Position of comment in each row of array CA.
B←≠\B\2≠/0,(B←BX∨BY)/BX ⍝ State of switch given BX=on & BY=off spikes.
N←(~B)+B\N ⍝ Expand N, but change fill item to one.
N←(NS×~B)+B\N ⍝ Expand N, but change fill item to NS.
IS←|¯11|+/+\10↑⍎¨C ⍝ ISBN check digit generator from C. C^.εNUM
IS←97+¯97|IS ⍝ SWIFT check digit from IS bank number.
APL Wiki