It's is possible that we have a different interpretation of what is the
problem to be solved.  My interpretation is the classic definition of
lexicographic ordering.  First, you order by column 0, resulting in groups
of rows with identical values in column 0.  Then, within each group, you
order by column 1, getting subgroups with identical values in columns 0 and
1.  Then, within each subgroup, you order by column 1+k, getting
subsubgroups with identical values in columns i.k.  The "twist" is that
each ordering in the process can be ascending or descending, to be
specified separately for each column.  I have seen system sort routines
which deliver exactly this (ahem) sort of functionality.

Therefore, for x=. ,/^:2 >{3#<i.3, the transposed result

   |: 1 1 _1 (] /: *"1 ) x
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2
2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0

is exactly what I intended and consistent with my interpretation of the
problem.

It's possible that your interpretation is what was asked in the original
question posed by Jimmy Gauvin.  No matter, I find my version an
interesting problem and that's the one I am solving.


On Mon, Jan 21, 2019 at 4:36 AM R.E. Boss <r.e.b...@outlook.com> wrote:

> >
> > On Sat, Jan 19, 2019 at 8:40 AM Roger Hui <rogerhui.can...@gmail.com>
> > wrote:
> >
> > > If the keys are numeric you can multiply the ascending column by 1 and
> > > the descending one by _1, and then apply /:  .
> > >
>
> It is not enough to multiply with 1 or _1 for ascending or descending
> columns. You might have to reorder the columns as well.
>
> Suppose the 3-column matrix x with
>    |:x=. ,/^:2 >{3#<i.3
> 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
> 0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2
> 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2
>  has to be sorted ascending by column 0, descending by column 2 and
> ascending by column 1, in that order.
>
> Multiplying columns by 1 1 _1 and sorting would deliver
>    |:1 1 _1( ]/: *"1 ) x
> 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
> 0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2
> 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0
>
> Whereas this is (the transposed of) what we want
>    |: 1 1 _1( ]/: *"1)&.:(0 2 1&C."1)  x
> 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
> 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2
> 2 2 2 1 1 1 0 0 0 2 2 2 1 1 1 0 0 0 2 2 2 1 1 1 0 0 0
>
>
> R.E. Boss
> ----------------------------------------------------------------------
> 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