Wasn't there some kind of "Flip It" code with simple graphics posted a while ago for a problem very similar to this one? I can't find it but it sounds familiar...
On Fri, Feb 5, 2010 at 1:29 PM, Roger Hui <[email protected]> wrote: > A slight improvement: > > N=: 3 3 (j e. (9$0 1 0 1 1 1) # ,);._3 ] _,(_,.j,._),_: j=. i.n,n > N -: Neighbors > 1 > > > > ----- Original Message ----- > From: Roger Hui <[email protected]> > Date: Friday, February 5, 2010 8:57 > Subject: Re: [Jprogramming] Lights Out! > To: Programming forum <[email protected]> > > > Instead of m=: *:n I should have used _ . Also, <"2 > > Neighbors > > is an interesting display. > > > > N=: 3 3 (j e. (9$_1 1 _1 1 1 1) * ,);._3 ] > > _,(_,.j,._),_ [ j=. >:i.n,n > > N -: Neighbors > > 1 > > $ N > > 5 5 5 5 > > > > <"2 N > > +---------+---------+---------+---------+---------+ > > |1 1 0 0 0|1 1 1 0 0|0 1 1 1 0|0 0 1 1 1|0 0 0 1 1| > > |1 0 0 0 0|0 1 0 0 0|0 0 1 0 0|0 0 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 0 0| > > |0 0 0 0 0|0 0 0 0 0|0 0 0 0 0|0 0 0 0 0|0 0 0 0 0| > > |0 0 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 1 0 0 0|0 0 1 0 0|0 0 0 1 0|0 0 0 0 1| > > |1 1 0 0 0|1 1 1 0 0|0 1 1 1 0|0 0 1 1 1|0 0 0 1 1| > > |1 0 0 0 0|0 1 0 0 0|0 0 1 0 0|0 0 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 0 0| > > |0 0 0 0 0|0 0 0 0 0|0 0 0 0 0|0 0 0 0 0|0 0 0 0 0| > > +---------+---------+---------+---------+---------+ > > |0 0 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 1 0 0 0|0 0 1 0 0|0 0 0 1 0|0 0 0 0 1| > > |1 1 0 0 0|1 1 1 0 0|0 1 1 1 0|0 0 1 1 1|0 0 0 1 1| > > |1 0 0 0 0|0 1 0 0 0|0 0 1 0 0|0 0 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 0 0| > > +---------+---------+---------+---------+---------+ > > |0 0 0 0 0|0 0 0 0 0|0 0 0 0 0|0 0 0 0 0|0 0 0 0 0| > > |0 0 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 1 0 0 0|0 0 1 0 0|0 0 0 1 0|0 0 0 0 1| > > |1 1 0 0 0|1 1 1 0 0|0 1 1 1 0|0 0 1 1 1|0 0 0 1 1| > > |1 0 0 0 0|0 1 0 0 0|0 0 1 0 0|0 0 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 0 0| > > |0 0 0 0 0|0 0 0 0 0|0 0 0 0 0|0 0 0 0 0|0 0 0 0 0| > > |0 0 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 1 0 0 0|0 0 1 0 0|0 0 0 1 0|0 0 0 0 1| > > |1 1 0 0 0|1 1 1 0 0|0 1 1 1 0|0 0 1 1 1|0 0 0 1 1| > > +---------+---------+---------+---------+---------+ > > > > > > > > ----- Original Message ----- > > From: Dan Bron <[email protected]> > > Date: Friday, February 5, 2010 4:43 > > Subject: Re: [Jprogramming] Lights Out! > > To: 'Programming forum' <[email protected]> > > > > > Roger wrote: > > > > n =: 5 > > > > Neighbors=: 3 3 ((>:i.n,n) e. (9$_1 1 _1 1 1 1) * ,);._3 >:m > > > ,(m,.(i.n,n),.m),m=: *:n > > > > out =: [ ~: Neighbors {~ <@] > > > > > > Now that's what I call array-oriented! Generating the 4- > > > dimensional catalog > > > of boards, indexed by light. And I like the use of > > > tessellation (my > > > original solution also used ;._3 but not so > > > elegantly). Wonderful. > > > > > > In gratitude, I present a different way to calculate > > Neighbors, > > > which may > > > reveal something of the game's nature: > > > > > > Neighbors =: #: (0 ,. -<:i.n) |.!.0 / (,~n) {. > > (,. ] ,.~ -: <.@ > > > * 7 3 {~ # {.1:) 2^i.-n > > > > > > Note the all the twos (2&^ and -: and #:). The only wart > > > in the expression > > > is ... <.@ * 7 3 {~ # {.1: where we're mostly > > > multiplying by 7, except at > > > the ends where we multiply by 3 (and at the trailing end we > > also > > > do not > > > halve, hence <.). I suppose this is this > > > representation's expression of the > > > edge conditions, as the *:n border is in yours. > > > > > > Since this wart shows up in every representation, perhaps it > > is > > > inescapable.Or maybe it is a part of the definition of the > > > game. There are some > > > versions where the board is toroidal, i.e. the top "wraps > > > around" to the > > > bottom and so does the left to the right, so there are no > > edges > > > or corners > > > (and so no edge or corner cases). > > > > > > -Dan > > > > > > PS: The multi-axis features of |. and > > > {. is what makes this expression > > > sweet. In Raul's solution, if we implemented the feature > > > request at [1], he > > > could have similarly sweetened his expression. > > > > > > [1] > > > > > > http://www.jsoftware.com/jwiki/System/Interpreter/Requests#redefineu.3B.0y > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > -- Devon McCormick, CFA ^me^ at acm. org is my preferred e-mail ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
