Eugene McDonnell (worked very closely with Ken Iverson) wrote a wonderful book 
“At Play With J”, available here;
http://code.jsoftware.com/wiki/At_Play_With_J

In which the chapter on “volutes” offers a tacit derivation of a non looping 
alternative to WRAP.  An involute counts from outside in to the centre, an 
evolute counts from the centre out (spirals), produced with significant 
contributions from Roger Hui and Joey Tuttle (in J Forum).

Eugene’s tacit Volute solution is replaced below (read the article for the full 
derivation).
http://code.jsoftware.com/wiki/Doc/Articles/Play132
=========================================
   evJKT1=:<:@+: $ _1: , ] , 1: , -
   evJKT0=:}:@(2: # >:@i.)
   evJKT2=:_1&|.@(evJKT0 # evJKT1)
   evJKT=:(,~ $ /: @ (+/\) @ evJKT2)
=========================================
   ] a=:1+evJKT 5
25 24 23 22 21
10 9 8 7 20
11 2 1 6 19
12 3 4 5 18
13 14 15 16 17

To solve the manhattan distance I “find” the (x,y) coordinate of a requested 
value, and also the value of 1 (origin), then do +/ | -/ of the 2 (x,y) coords 
using the function md …
   loc=: $@] #: (,@] i. [)
   20 1 loc"0 2 a
1 4           NB. coords of requested point (here 20 in above matrix)
2 2           NB. and value of ‘1'

   md=: [: +/ [: | [: -/ ] loc"0 2~ 1 ,~ [
   20 md a
3

Regards Rob

> On 4 Dec 2017, at 1:27 pm, Joe Bogner <[email protected]> wrote:
> 
> Hi Jimmy - I'm also working with WRAP from the phrases. I messed around
> with trying to understand https://oeis.org/A054552 but it seemed more
> complicated than I wanted to undertake.  Here's my exploration of my
> solution for part 1
> 
> I'm using this currently to locate the x/y coordinate (probably a better
> way?) within a grid
> 
> ((#~ *)@:,  ,. (I.@:*@:,)) I. (0&=)
> 
> ((#~ *)@:,  ,. (I.@:*@:,)) I. (0&=) (3 WRAP 0)
> 3 3
> 
>   (3 WRAP 0)
> 42 43 44 45 46 47 48
> 41 20 21 22 23 24 25
> 40 19  6  7  8  9 26
> 39 18  5  0  1 10 27
> 38 17  4  3  2 11 28
> 37 16 15 14 13 12 29
> 36 35 34 33 32 31 30
> 
> 
> For my problem -- 347991 -- what's the smallest square grid to satisfy it?
> 
>   %: 347991
> 
> 589.908
> 
> 
> What argument for wrap is needed?
> 
> 
> -: %: 347991
> 
> 294.954
> 
> 
> Find my target:
> 
> 
> ((#~ *)@:, ,. (I.@:*@:,)) I. (347991&=) (1+(295 WRAP 0))
> 
> 110 590
> 
> 
> 
> 
> Try the smaller just to be sure (returns blank)
> 
>   ((#~ *)@:, ,. (I.@:*@:,)) I. (347991&=) (1+(294 WRAP 0))
> 
> 
> Find origin (not really needed but still interesting to me)
> 
> 
>  ((#~ *)@:, ,. (I.@:*@:,)) I. (1&=) (1+(295 WRAP 0))
> 
> 295 295
> 
> 
> Calc manhattan distance
> 
> 
>   (| (110-295)) + (|(590-295))
> 
> 480
> 
> 
> My answer was 480
> 
> 
> Not particularly pretty but got to the right answer... It needs more work
> to be reusable
> 
> 
> 
> 
> 
> On Sun, Dec 3, 2017 at 9:01 PM, Jimmy Gauvin <[email protected]> wrote:
> 
>> Hi,
>> 
>> has anybody found something better than a "do. while." to calculate the
>> spiral neighborhood count?
>> 
>> Is there some underlying mathematical structure that I am not aware of?
>> 
>> 
>> 
>> Thanks,
>> 
>> 
>> 
>> 
>> WRAP is from http://www.jsoftware.com/help/phrases/grids.htm
>> 
>> spw is the result of the neighbor calculation
>> 
>> 
>> (|.2 WRAP 1){spw
>> 
>> 147 142 133 122 59
>> 
>> 304 5 4 2 57
>> 
>> 330 10 1 1 54
>> 
>> 351 11 23 25 26
>> 
>> 362 747 806 880 931
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> 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