Since we know the field is not larger than  1000 1000  :

           boxen =:  [: #@:~. (i. 1000 1000) ([: ;@:] <@:,;.0)~ [: ([ ,: 
-~)/"(2) 2 2 $ "1 ]  
        
           A     =:  _4 ]\  1 2 4 4   2 3 5 7    3 1 6 5   7 3 8 6
        
           boxen A
        26
           
It won't scale well,  but it's a correct and comprehensive answer to the 
question as asked, and I produced in less than half a minute.  There's value in 
that.   Screw benchmarks.


BTW, there's a bug in J:

           
           f     =:  ([: ;    <@:,;.0~)
           g     =:  ([: ;    <@:,;.0 )~  NB.  Should be equivalent
        
           (i. 5 5) f 1 ,: 2 
        5 6 7 8 9 10 11 12 13 14
           
           (i. 5 5) g 1 ,: 2 
        |domain error: g
        |   (i.5 5)    g 1,:2
           
           h     =:  ([: ;@:] <@:,;.0 )~  NB.  Workaround
        
           (i. 5 5) h 1 ,: 2 
        5 6 7 8 9 10 11 12 13 14

-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to