> On Dec 3, 2017, at 7:01 PM, Jimmy Gauvin <[email protected]> wrote: > > has anybody found something better than a "do. while." to calculate the > spiral neighborhood count?
Amusingly, someone made a video about a cool trick for doing this in J, it's about 1/3rd of y'all's Youtube presence: https://www.youtube.com/watch?v=dBC5vnwf6Zw&t=282s <https://www.youtube.com/watch?v=dBC5vnwf6Zw&t=282s> That said, I didn't see how to solve this one even with the spiral generated until this morning in the shower and haven't had time to work on it until now. My approach would basically be to generate the spiral of the right size and then do the index-decode trick from this S.O. answer: https://stackoverflow.com/questions/39686977/j-coordinates-with-specific-value <https://stackoverflow.com/questions/39686977/j-coordinates-with-specific-value> Once you have the coordinates, the sum of absolute value of the x- and y-coordinate should be the solution, but you'll have to do some kind of offset fiddling to compensate for 0,0 being in the middle rather than the lower-left. Since I haven't completed part A yet, I haven't seen part B. -- Daniel Lyons ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
