not as concise, but an alternative:

makeTable =: ( ((<0;0)&{:: ; (<a:;1)&{) /.~ (<a:;0)&{)

makeTable (animals,.ids)
┌────┬──┬──┬──┬──┬─┐
│bird│1 │8 │14│  │ │
├────┼──┼──┼──┼──┼─┤
│cow │2 │3 │5 │6 │7│
├────┼──┼──┼──┼──┼─┤
│dog │4 │9 │11│13│ │
├────┼──┼──┼──┼──┼─┤
│cat │10│  │  │  │ │
├────┼──┼──┼──┼──┼─┤
│pig │12│15│  │  │ │
└────┴──┴──┴──┴──┴─┘

ids=:'one';'two';'three';'four';'five';'six';'seven';'eight';'nine';'ten';'eleven';'twelve';'thirteen';'fourteen';'fifteen'

makeTable (animals,.ids)
┌────┬──────┬───────┬────────┬────────┬─────┐
│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 11:58 AM, Raul Miller <[email protected]> wrote:
> I'd have used ;:inv instead of ;:^:_1 like EelVex used (same
> operation, but slightly shorter and I think slightly easier to read).
>
> Generally, ;:inv is perfect for taking a boxed list of strings and
> getting a space separated string.
>
> Commas are a bit more work (and if you want the last comma to be the
> word 'and' with spaces separating it from adjacent words, and a space
> after each comma), that's a bit more work...
>
> --
> Raul
>
>
> On Fri, Mar 4, 2016 at 11:20 AM, 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to