> -----Original Message-----
> From: [email protected] [mailto:programming-
> [email protected]] On Behalf Of Ben Gorte - LR
> Sent: Tuesday, January 10, 2012 3:41 PM
> To: Programming forum ([email protected])
> Subject: [Jprogramming] Boxes of different lengths
>
> Dear Forum,
>
> Perhaps it is a beginners question, but somehow I cannot come up with a
> decent answer.
>
> I have a matrix like of position-value pairs like:
>
> 0 0 1 1 1 1 2 2 2 2 2 4 4 4 5 5
> 5 0 7 8 9 2 2 5 5 5 3 8 0 0 5 6
>
> (it could also be transposed), and I would like to have a list of boxes:
>
> +---+-------+---------++-----+---+
> |5 0|7 8 9 2|2 5 5 5 3||8 0 0|5 6|
> +---+-------+---------++-----+---+
>
> So the values are placed in boxes according to the positions.
>
> My matrix above is sorted (from left to right), but probably this is not
> essential for most solutions. Furthermore, the order of the elements
within
> the boxes of the result is not important for the remainder of my
algorithm.
>
> I have a solution that loops through the matrix from left to right, but it
is way
> too slow (and it does not look like J). Isn't there a better way?
a=.0 0 1 1 1 1 2 2 2 2 2 4 4 4 5 5
a=.a,:5 0 7 8 9 2 2 5 5 5 3 8 0 0 5 6
a
0 0 1 1 1 1 2 2 2 2 2 4 4 4 5 5
5 0 7 8 9 2 2 5 5 5 3 8 0 0 5 6
(0{a)</.1{a
----T-------T---------T-----T---┐
│5 0│7 8 9 2│2 5 5 5 3│8 0 0│5 6│
L---+-------+---------+-----+----
http://www.jsoftware.com/help/dictionary/d421.htm
Enjoy!
--
Stefano
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm