Ah, yes. Here is a small test case:
table =: "."0;._2'000101101001101 000100000000100 100000011100000
000000010010010 000000010000000 011001011110010 000000000000000
001111001100011 '
table
0 0 0 1 0 1 1 0 1 0 0 1 1 0 1
0 0 0 1 0 0 0 0 0 0 0 0 1 0 0
1 0 0 0 0 0 0 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 1 0 0 1 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 1 1 0 0 1 0 1 1 1 1 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 0 0 1 1 0 0 0 1 1
]j=: i,I.s{~ i=.(i.>./)+/ s=.(= >./@,) (-.=i.#table)*.(+/ . *. |:)
table
5 7
]k=: I.*./ j{table
2 5 8 9 13
Now, let's say that I wish to limit the number of columns to 2.
In this case, I would expect the answer to be:
j
0 5 7
k
5 8
or
j
2 5 7
k
8 9
Either of these combinations would be useful answers.
Here is perhaps a more interesting example:
table =: "."0;._2'100111011111011 010101100010010 111101111010111
101010110010000 010000111010101 100101100100101 111110011101100
111111110011011 '
table
1 0 0 1 1 1 0 1 1 1 1 1 0 1 1
0 1 0 1 0 1 1 0 0 0 1 0 0 1 0
1 1 1 1 0 1 1 1 1 0 1 0 1 1 1
1 0 1 0 1 0 1 1 0 0 1 0 0 0 0
0 1 0 0 0 0 1 1 1 0 1 0 1 0 1
1 0 0 1 0 1 1 0 0 1 0 0 1 0 1
1 1 1 1 1 0 0 1 1 1 0 1 1 0 0
1 1 1 1 1 1 1 1 0 0 1 1 0 1 1
]j=: i,I.s{~ i=.(i.>./)+/ s=.(= >./@,) (-.=i.#table)*.(+/ . *. |:)
table
2 7
]k=: I.*./ j{table
0 1 2 3 5 6 7 10 13 14
OK, let's say that I wish to limit the number of columns to 5
and still wish to maximize the number of rows... by inspection, it
would appear that one valid answer would be:
j
0 6 7
k
0 3 4 7 11
wow... that was tougher than I thought to do by inspection... it
could be that I'm totally wrong (meaning that I didn't actually optimize
the number of rows).
I tried the following expression, and that is obviously wrong:
]j=: i,I.s{~ i=.(i.>./)+/ s=. 5=(-.=i.#table)*.(+/ . *. |:) table
5 0 7
]k=: I.*./ j{table
0 3 5 14
This didn't work either:
f =: 4 : 0
y =. ,y
(y>x)#(i.#y)
)
]j=: i,I.s{~ i=.(i.>./)+/ s=. 5 f}(-.=i.#table)*.(+/ . *. |:) table
2 0 0 0 0 0 1 1 1 1 1 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7
-- Glenn
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Oleg Kobchenko
Sent: Tuesday, July 03, 2007 12:21 AM
To: Programming forum
Subject: Re: [Jprogramming] J expression question
One approach would be to place a different
value where it uses maximum.
Is there a small example, as before, that
would showcase a sub-maximal selection?
--- "Glenn M. Lewis" <[EMAIL PROTECTED]> wrote:
> I'm sorry, I wasn't clear... I meant that I wanted to limit Oleg's
> algorithm to maximize the number of columns, but up to a limit of 64.
> If I don't limit the number of columns, the result gives a trivial
> combination of two rows with a huge number of columns, as Leo pointed
out.
> -- Glenn
>
> Raul Miller wrote:
> > On 7/3/07, Glenn M. Lewis <[EMAIL PROTECTED]> wrote:
> >> OK, so now I'm trying to limit the result to a maximum of 64
columns.
> >
> > I don't understand why you want this, but here's a
> > verb to limit a list to the first 64 (or less) entries:
> > ({.~ 64 <. #)
> >
> > For example:
> > k=: ({.~ 64 <. #) I.*./ j{table
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm