See also Eugene McDonnell's APL88 paper,
Life: Nasty, Brutish, and Short
http://www.jsoftware.com/papers/eem/life.htm

(The "Life" refers to the Game of Life.)



----- Original Message -----
From: Dan Bron <[email protected]>
Date: Saturday, February 6, 2010 8:19
Subject: Re: [Jprogramming] Lights Out!
To: 'Programming forum' <[email protected]>

> Raul wrote:
> >  out=: [ ~: 1 1}. _1 _1}. -...@] |. (0 1 0,1,:0 1 0) {.~ 2 + $...@[
> 
> Roger wrote:
> >   N=: 3 3 (j e. (9$0 1 0 1 1 1) # ,);._3 ] 
> _,(_,.j,._),_: j=. i.n,n
> >   out      =: [ ~: N {~ <@]
> 
> Raul calculates the neighborhood at runtime.  Roger 
> generates the entire
> catalog of neighborhoods in advance.  We could take a 
> hybrid approach; we
> don't have to generate the entire catalog of neighborhoods, but 
> if we store
> just enough, we can still use cut and avoid explicit mention of 
> the edge-
> and corner-cases:
> 
>            
> Nd      =.  (,~>:n) |. (,~>:+:n) 
> {. #: 2 7 2
>            
> out     =:  ~: Nd ];.0~ n&([ ,:~ 1 + -)
>       
>            
> Neighbors -: ($&0 out "_ 1 ] #: i.) ,~n
>       1
> 
> I haven't checked, but of the three, I'd assume Roger's to be fastest,
> because having generated and cached the neighborhood catalog, 
> when applied,
> his out needs only to do one { and (and then the  ~:  
> which all the verbs
> must do).  This is in contrast to the other approaches 
> which do more
> calculations per application.  
> 
> Another contrast is between the "structural" and "mathematical" 
> approaches,where the arrays are represented and manipulated 
> differently (e.g. in terms
> of shapes vs in terms of values).  I'm going to see if I 
> can make another
> hybrid, this time mixing Raul's runtime approach with the 
> mathematical 2&^.
> representation I touched on yesterday (which took Roger's 
> catalog approach).
> 
> -Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to