In general I agree with Don that perhaps there are better ways to get the
end result.
However I did have a play and came up with the following way to box the
columns of a table that is about twice as fast and twice as lean as the
transpose method.
ab=: >: ?. 1e6 4 $ 9
$ab
1000000 4
10 timespacex '(i.@{:@$ {"1&.> <) ab'
0.019139 3.35588e7
10 timespacex '<"_1 |: ab'
0.0461787 7.54998e7
On Mon, Nov 26, 2012 at 2:33 PM, Don Guinn <[email protected]> wrote:
> I don't think that there is a way to box by column other than transposing.
> However, it is not really necessary to box each column (or row if you
> transpose) to get your desired answer, which I assume is that you are
> looking for columns containing 9 unique digits. All you really need it the
> count of unique digits in each column. Is that correct? Given that, look
> for columns which contain 9 unique digits.
>
> ar =: >: ?. 9 4 $ 9
> ar
> 1 3 2 4
> 3 2 5 2
> 9 8 4 6
> 5 9 8 6
> 7 2 5 9
> 3 7 2 8
> 1 2 7 9
> 5 1 9 7
> 8 7 6 9
> (<@~.)"1 |:ar
> +-----------+-----------+-------------+-----------+
> |1 3 9 5 7 8|3 2 8 9 7 1|2 5 4 8 7 9 6|4 2 6 9 8 7|
> +-----------+-----------+-------------+-----------+
> (#@~.)"1 |:ar
> 6 6 7 6
>
> On Sun, Nov 25, 2012 at 6:05 PM, Nick Simicich <[email protected]> wrote:
>
> > I am trying to use the new gmail - and I have no idea why this partial
> > message was sent prematurely. I apologize, please ignore the earlier
> > version.
> >
> > ---------- Forwarded message ----------
> > From: Nick Simicich <[email protected]>
> > Date: Sun, Nov 25, 2012 at 4:24 PM
> > Subject: Boxing by columns
> > To: Programming forum <[email protected]>
> >
> >
> > OK, I have a simple problem. I am writing a mathdoku helper in J, just
> > for grins (and because it can run on my Android phone).
> >
> > At one point I have what might a number of solutions (generally between
> 10
> > and a max of a couple hundred). They will be in a variable that will
> > contain each solution boxed. Thus, it will look like:
> >
> > [1 2 3 4][4 2 3 1][3 1 2 4] etc. Each solution has the same length.
> >
> > I need to look at the contents of each column. Essentially, I want to
> take
> > the nub of each column and sort the results for display - so that I can
> > display the possible results at each position.
> >
> > So I want to take this variable which is boxed by column and re-box it by
> > row.
> >
> > This is the routine I am currently using to display my data:
> >
> > rr =: [: (([: (/:~) ~.)L:_1) ([: (<"_1) ([: |: >))
> >
> > The above works. But it bothers me for this reason - I am transposing
> the
> > array here so that I can rebox it by row:
> >
> > (<"_1) ([: |: >)
> >
> > I am trying to determine if there is any way to take a two dimensional
> > array and to box the data in the array by column - I thought that there
> was
> > something I could specify in the rank for box, but I can't figure out
> what
> > it might be - or is there a better way to box by column?
> >
> >
> >
> > To try ans simplify, suppose you create an array with
> >
> > ar =: >: ?. 9 4 $ 9
> >
> > If your random number generator and ?. works like mine does,
> >
> > +/,ar is 191
> >
> >
> > <"_1 |: ar
> >
> > gives me 4 boxes - and with data of this size, it is not important that
> you
> > have transposed the data. If you had 1000000 rows (I have tried it)
> there
> > is a noticeable pause when you transpose.
> >
> > It is possible to extract a column with 0{"1 ar - or a row with 0{ ar
> >
> > It is possible to sum on columns or rows by using the rank adverb.
> >
> > But I can't figure out how to box by column -
> >
> > < ar produces a single box
> > <"1 ar boxes by row - 9 boxes.
> > <"_1 ar boxes by row.
> >
> > <"(1 _ 1) ar boxes by row.
> >
> > I have tried maybe 20 3 digit combinations and I can't get it to select
> the
> > columns and box them.
> >
> > Maybe there is no way to do this - I have asked a few questions here,
> none
> > for many months because once I understood more about rank some of my
> > questions went away. But this one issue escapes me - maybe someone could
> > undertake an answer and an explanation? Or an explanation as to why it
> > just won't work?
> >
> > I am thinking that an alternative would be to extract one column at a
> time
> > and then produce the boxes from those columns and stack them together -
> but
> > I am unsure of how to do that, either.
> >
> > And, again, I am sorry that I posted a partial unedited question.
> >
> >
> > --
> > Of course I can ride in the carpool lane, officer. Jesus is my constant
> > companion.
> > ----------------------------------------------------------------------
> > 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