Just for the record, I include my solution for guard in the following.
I wanted to find a purely tacit version of guard but I couldn't. You
can see the struggle; it's complex. As you might notice, I tried to
follow the repetitive pattern shown in my original 3d version. Of
course the final code is more complex than Raul's guard, which takes
use of "take."

enc=: 0,~0,]
er=: enc"
erstep=: 3 : '(>:r) ; (r=.>{.y) er >{:y'
guard=:[: >@{: ([EMAIL PROTECTED]:([EMAIL PROTECTED]@[) (1 ; ]))

   guard >:i. 2
0 1 2 0
   guard >:i. 2 3
0 0 0 0 0
0 1 2 3 0
0 4 5 6 0
0 0 0 0 0
   guard >:i. 2 3 4
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  2  3  4 0
0  5  6  7  8 0
0  9 10 11 12 0
0  0  0  0  0 0

0  0  0  0  0 0
0 13 14 15 16 0
0 17 18 19 20 0
0 21 22 23 24 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


2008/6/17 June Kim <[EMAIL PROTECTED]>:
> 2008/6/17 Raul Miller <[EMAIL PROTECTED]>:
>> On 6/17/08, June Kim <[EMAIL PROTECTED]> wrote:
>>> Now, the next part. You want to make the code general, so it can treat
>>> n-dimension.
>> ...
>>> How would you generalize guard code in J style? I believe there is a
>>> simple solution.
>>
>> guard=: ({.~ _1 - $)@({.~ 1 + $)
>
> Great. I always tend to underestimate the power and usefulness of "take".
>
>
>>   guard 1 2 3
>> 0 1 2 3 0
>>   guard 1 2 3,:4 5 6
>> 0 0 0 0 0
>> 0 1 2 3 0
>> 0 4 5 6 0
>> 0 0 0 0 0
>>
>> --
>> Raul
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to