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
