Thanks -- that's much nicer than what I wrote. I don't think it
provides the correct answer: each of the rows and columns must
individually sum to a positive number (or zero). Then you minimize the
overall sum. For the matrix given by the following line I think the
best possible sum is 3822.
count =: */ shape =: $ list=: ((_1*(c=:14))]\]) (_100 + ?. (420 $
200))
There are two possible improvements. First, I'm brute forcing the
answer, and the complexity of my method goes up exponentially with the
size of the smallest dimension of the matrix. So if there's a more
efficient method than that, I'm curious to hear about it. But I'm more
interested in simple improvements to my J, since I'm still very weak
at it.
regards,
Geoff
On Mar 24, 2008, at 11:59 AM, Arie Groeneveld wrote:
Here's another possibility
column wise gives:
CW=:3 :'((({.shape)$1 _1)*((\:@:|"1 y){ |y)) (\:@:|"1 y) } y'"1&.|:
list
row wise:
RW=:3 :'((({:shape)$1 _1)*((\:@:|"1 y){ |y)) (\:@:|"1 y) } y'"1 list
Minimum is:
(([:(=<./) +/@:,"_1)#]) CW,:RW
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm