Multisplit: Difference between revisions
Content added Content deleted
m (Mark solutions as needing review) |
(J: review, clarification, and added missing variable from example) |
||
Line 8: | Line 8: | ||
=={{header|J}}== |
=={{header|J}}== |
||
{{needs-review|J}} |
|||
<lang j>multisplit=:4 :0 |
<lang j>multisplit=:4 :0 |
||
'sep begin'=.|:t=. y /:~&.:(|."1)@;@(i.@#@[ ,.L:0"0 I.@E.L:0) x |
'sep begin'=.|:t=. y /:~&.:(|."1)@;@(i.@#@[ ,.L:0"0 I.@E.L:0) x |
||
Line 26: | Line 25: | ||
First find all potentially relevant separator instances, and sort them in increasing order, by starting location and separator index. <code>sep</code> is separator index, and <code>begin</code> is starting location. <code>end</code> is ending location. |
First find all potentially relevant separator instances, and sort them in increasing order, by starting location and separator index. <code>sep</code> is separator index, and <code>begin</code> is starting location. <code>end</code> is ending location. |
||
Then, loop through the possibilities, skipping over those which |
Then, loop through the possibilities, skipping over those separators which would overlap with previously used separators. |
||
Example use: |
Example use: |
||
<lang j> S |
<lang j> S=:'a!===b=!=c' |
||
S multisplit '==';'!=';'=' |
|||
┌───┬───┬───┬───┬─┐ |
┌───┬───┬───┬───┬─┐ |
||
│a │ │b │ │c│ |
│a │ │b │ │c│ |