(~.@{.,.<@(;:^:_1)/./)list2
┌────┬─────────────────────────┐
│bird│one eight fourteen       │
├────┼─────────────────────────┤
│cow │two three five six seven │
├────┼─────────────────────────┤
│dog │four nine eleven thirteen│
├────┼─────────────────────────┤
│cat │ten                      │
├────┼─────────────────────────┤
│pig │twelve fifteen           │
└────┴─────────────────────────┘


On Fri, Mar 4, 2016 at 6:20 PM, Skip Cave <[email protected]> wrote:

> Both Henry &
> ​ ​
> Raul came up with
> ​what is ​
> likely the shortest solution:
>
>    (~.@[ ,. [/.)/ list
>
> ​I like ​Henry's second approach, even though it is a bit longer:
>
>     (~.@[ ,. <@;/.)/ list
>
> ┌────┬─────────┐
>
> │bird│1 8 14   │
>
> ├────┼─────────┤
>
> │cow │2 3 5 6 7│
>
> ├────┼─────────┤
>
> │dog │4 9 11 13│
>
> ├────┼─────────┤
>
> │cat │10       │
>
> ├────┼─────────┤
>
> │pig │12 15    │
>
> └────┴─────────┘
>
> ​However, what if the tag IDs were text, instead of numerical?​
>
> animals =:
>
> 'bird';'cow';'cow';'dog';'cow';'cow';'cow';'bird';'dog';'cat';'dog';'pig';'dog';'bird';'pig'
> ids
>
> =:'one';'two';'three';'four';'five';'six';'seven';'eight';'nine';'ten';'eleven';'twelve';'thirteen';'fourteen';'fifteen'
>
> list2 =. animals,:ids
>
>
> Using Henry's second verb:
>
>
>      (~.@[ ,. <@;/.)/ list2
>
> ┌────┬──────────────────────┐
>
> │bird│oneeightfourteen      │
>
> ├────┼──────────────────────┤
>
> │cow │twothreefivesixseven  │
>
> ├────┼──────────────────────┤
>
> │dog │fournineeleventhirteen│
>
> ├────┼──────────────────────┤
>
> │cat │ten                   │
>
> ├────┼──────────────────────┤
>
> │pig │twelvefifteen         │
>
> └────┴──────────────────────┘
>
>
> Can you separate the IDs with spaces (or commas) between the IDs?
>
> Modifying the original list by inserting spaces isn't allowed.
>
> Skip Cave
>
> ᐧ
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to