On Thu, Feb 4, 2010 at 5:07 PM, Dan Bron <[email protected]> wrote:

>           ] BOARD0 =: 5 5 $ 0 0 0 0 0   0 0 0 0 0  1 0 1 0 1  0 0 0 0 0   0
> 0 0 0 0

...

         PUSH   =: 3 2
>
> can you write a dyad   out   such that:
>
>           ] BOARD1 =: BOARD0 out PUSH
>        0 0 0 0 0
>        0 0 0 0 0
>        1 0 0 0 1
>        0 1 1 1 0
>        0 0 1 0 0
>
>
> in an elegant, array-oriented way?


out=: [ ~: 1 1}. _1 _1}. -...@] |.!.0 (0 1 0,1,:0 1 0) {.~ 2 + $...@[

If PUSH were represented using negative numbers,
-...@] could be replaced with ]

Alternatively, if we can assume a 5x5 board,

out5x5=: [ ~: 1 1}. _1 _1}. (7 7{.0 1 0,1,:0 1 0) |.!.0~ -...@]

(With the same comment about the possible alternative
representation for PUSH.  But this one could also be
implemented as a hook by dropping the [ on the left.)

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

Reply via email to