Thank you. I will take a look.

Here's some other ideas.

Naive simple approach, similar to Andrew's.
Much slower than CONTIG, but leaner.

   A=: "."0;._2 '111111 100101 100101 100011 101001 111111 '
   B=: 1 (<1 1) } 2=A
   sh=: _1&(|.!.0"1) +. 1&(|.!.0"1) +. _1&|. +. 1&|. +. ]
   A ; B ; A (< sh)^:_ B
+-----------+-----------+-----------+
|1 1 1 1 1 1|0 0 0 0 0 0|0 0 0 0 0 0|
|1 0 0 1 0 1|0 1 0 0 0 0|0 1 1 0 0 0|
|1 0 0 1 0 1|0 0 0 0 0 0|0 1 1 0 0 0|
|1 0 0 0 1 1|0 0 0 0 0 0|0 1 1 1 0 0|
|1 0 1 0 0 1|0 0 0 0 0 0|0 1 0 1 1 0|
|1 1 1 1 1 1|0 0 0 0 0 0|0 0 0 0 0 0|
+-----------+-----------+-----------+

These expressions can be called a scanlines:

   (>./\.&.|: ; >./\&.|: ; >./\. ; >./\) B
+-----------+-----------+-----------+-----------+
|0 0 0 0 0 0|0 0 0 0 0 0|0 1 0 0 0 0|0 0 0 0 0 0|
|1 1 0 0 0 0|0 1 1 1 1 1|0 1 0 0 0 0|0 1 0 0 0 0|
|0 0 0 0 0 0|0 0 0 0 0 0|0 0 0 0 0 0|0 1 0 0 0 0|
|0 0 0 0 0 0|0 0 0 0 0 0|0 0 0 0 0 0|0 1 0 0 0 0|
|0 0 0 0 0 0|0 0 0 0 0 0|0 0 0 0 0 0|0 1 0 0 0 0|
|0 0 0 0 0 0|0 0 0 0 0 0|0 0 0 0 0 0|0 1 0 0 0 0|
+-----------+-----------+-----------+-----------+

They might improve performance.


--- "R.E. Boss" <[EMAIL PROTECTED]> wrote:

> I made some improvements later on, e.g. extended it to >2 dimensions. 
> Don't know if I made performance improvements.
> It reminds me also to the solution I found for the components in graphs.
> Perhaps you could use that. See
> http://www.jsoftware.com/pipermail/programming/2006-September/003258.html 
> 
> R.E. Boss
> 
> 
> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Namens Oleg Kobchenko
> Verzonden: dinsdag 1 mei 2007 10:51
> Aan: Programming forum
> Onderwerp: RE: [Jprogramming] A mazing grace
> 
> Yes, this is similar. However for shape 1800 1800,
> it takes about 270Mb of RAM and a few seconds
> 
>    CONTIG 300#300#"1 ...
> 
> I was thinking maybe a specific version would be
> faster and leaner? E.g. because it is and if it stays
> boolean it might get optimal treatment by special code.
> 
> 
> --- "R.E. Boss" <[EMAIL PROTECTED]> wrote:
> 
> > Is this (a more general solution of) what you mean?
> > 
> >    CONTIG "."0;._2 '111111 100101 100101 100011 101001 111111 '
> > 1 1 1 1 1 1
> > 1 3 3 1 5 1
> > 1 3 3 1 5 1
> > 1 3 3 3 1 1
> > 1 3 1 3 3 1
> > 1 1 1 1 1 1
> > 
> > See http://www.jsoftware.com/pipermail/general/2005-August/023910.html
> > 
> > R.E. Boss
> > 
> > 
> > 
> > -----Oorspronkelijk bericht-----
> > Van: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] Namens Oleg Kobchenko
> > Verzonden: dinsdag 1 mei 2007 9:15
> > Aan: Programming forum
> > Onderwerp: [Jprogramming] A mazing grace
> > 
> > This is probably a standard path-finding
> > algorithm, and possibly already implemented in J.
> > 
> > Given a boolean matrix, as shown in the first output, 
> > and an index with 0, e.g. (<1 1); return 1s for all 0s 
> > reachable with rectangular paths.
> > 
> >    "."0;._2 '111111 100101 100101 100011 101001 111111 '
> > 1 1 1 1 1 1
> > 1 0 0 1 0 1
> > 1 0 0 1 0 1
> > 1 0 0 0 1 1
> > 1 0 1 0 0 1
> > 1 1 1 1 1 1
> >    "."0;._2 '000000 011000 011000 011100 010110 000000 '
> > 0 0 0 0 0 0
> > 0 1 1 0 0 0
> > 0 1 1 0 0 0
> > 0 1 1 1 0 0
> > 0 1 0 1 1 0
> > 0 0 0 0 0 0
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to