Raul Miller wrote:
>     foo=: <^:{./.~ [: +/\ 0,2 ~:/\ ]

REB asked for a foo such that:

           foo 1 1 2 2 3 3 4 2 3 4 4 1 2 2 2 1
        +---+---------------------------+-+-------+-+
        |1 1|+---+---------+-+---------+|1|+-----+|1|
        |   ||2 2|+---+---+|2|+-+-----+|| ||2 2 2|| |
        |   ||   ||3 3|+-+|| ||3|+---+||| |+-----+| |
        |   ||   ||   ||4||| || ||4 4|||| |       | |
        |   ||   ||   |+-+|| || |+---+||| |       | |
        |   ||   |+---+---+| |+-+-----+|| |       | |
        |   |+---+---------+-+---------+| |       | |
        +---+---------------------------+-+-------+-+

Your foo gives:

           foo 1 1 2 2 3 3 4 2 3 4 4 1 2 2 2 1
        +---+-----+-------+-------+---+-----+---------+-+-------+-+
        |1 1|+---+|+-----+|+-----+|+-+|+---+|+-------+|1|+-----+|1|
        |   ||2 2|||+---+|||+---+|||2|||+-+|||+-----+|| ||2 2 2|| |
        |   |+---+|||3 3|||||+-+|||+-+|||3|||||+---+||| |+-----+| |
        |   |     ||+---+|||||4||||   ||+-+|||||4 4|||| |       | |
        |   |     |+-----+|||+-+|||   |+---+|||+---+||| |       | |
        |   |     |       ||+---+||   |     ||+-----+|| |       | |
        |   |     |       |+-----+|   |     |+-------+| |       | |
        +---+-----+-------+-------+---+-----+---------+-+-------+-+

That is, you have the depth of each element right, but you still need to
group the elements appropriately.  It helps to think of 1 1 2 2 3 3 4 2 3 4
4 1 2 2 2 1 as representing a parenthesized expression, with greater numbers
being more deeply nested.

-Dan

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to