Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
2 added 371 characters in body
source | link

APL 2925

1↓¨(1,∨⌿<\2=+\∘.=⍨a)⊂1,a←

Example:

]display 1↓¨(1,∨⌿<\2=+\∘.=⍨a)⊂1,a←2 1 1 2 3 2 2 4 5 6 7 3 7 0 5
┌→──────────────────────────────────────┐
│ ┌→──┐ ┌⊖┐ ┌→────────────┐ ┌⊖┐ ┌→┐ ┌⊖┐ │
│ │2 1│ │0│ │3 2 2 4 5 6 7│ │0│ │0│ │0│ │
│ └~──┘ └~┘ └~────────────┘ └~┘ └~┘ └~┘ │
└∊──────────────────────────────────────┘

Old One:

{1↓¨(1,(⍳⍴⍵)∊,{1↑1↓⍵}⌸⍵)⊂1,⍵}

This is a nice question for the key operator (⌸) which was introduced with Dyalog APL v14. It takes the left argument function ({1↑1↓⍵}) and gives it for each unique argument, the indices in the vector for that argument. Here I'm taking the second index, then i check which of the indices is present in this list ((⍳⍴⍵)∊) and use the resulting boolean for splitting the original vector.

Can be tried online here:

http://tryapl.org

APL 29

{1↓¨(1,(⍳⍴⍵)∊,{1↑1↓⍵}⌸⍵)⊂1,⍵}

This is a nice question for the key operator (⌸) which was introduced with Dyalog APL v14. It takes the left argument function ({1↑1↓⍵}) and gives it for each unique argument, the indices in the vector for that argument. Here I'm taking the second index, then i check which of the indices is present in this list ((⍳⍴⍵)∊) and use the resulting boolean for splitting the original vector.

Can be tried online here:

http://tryapl.org

APL 25

1↓¨(1,∨⌿<\2=+\∘.=⍨a)⊂1,a←

Example:

]display 1↓¨(1,∨⌿<\2=+\∘.=⍨a)⊂1,a←2 1 1 2 3 2 2 4 5 6 7 3 7 0 5
┌→──────────────────────────────────────┐
│ ┌→──┐ ┌⊖┐ ┌→────────────┐ ┌⊖┐ ┌→┐ ┌⊖┐ │
│ │2 1│ │0│ │3 2 2 4 5 6 7│ │0│ │0│ │0│ │
│ └~──┘ └~┘ └~────────────┘ └~┘ └~┘ └~┘ │
└∊──────────────────────────────────────┘

Old One:

{1↓¨(1,(⍳⍴⍵)∊,{1↑1↓⍵}⌸⍵)⊂1,⍵}

This is a nice question for the key operator (⌸) which was introduced with Dyalog APL v14. It takes the left argument function ({1↑1↓⍵}) and gives it for each unique argument, the indices in the vector for that argument. Here I'm taking the second index, then i check which of the indices is present in this list ((⍳⍴⍵)∊) and use the resulting boolean for splitting the original vector.

Can be tried online here:

http://tryapl.org

1
source | link

APL 29

{1↓¨(1,(⍳⍴⍵)∊,{1↑1↓⍵}⌸⍵)⊂1,⍵}

This is a nice question for the key operator (⌸) which was introduced with Dyalog APL v14. It takes the left argument function ({1↑1↓⍵}) and gives it for each unique argument, the indices in the vector for that argument. Here I'm taking the second index, then i check which of the indices is present in this list ((⍳⍴⍵)∊) and use the resulting boolean for splitting the original vector.

Can be tried online here:

http://tryapl.org