This step counting verb uses lengths of equilateral hexagonal grid, taking that step or apparently quantum tunneling pair of optimal steps.  I have not tried to understand it, but it works.

DIRS=:;:a=:'ne n nw sw s se'
('a'~)=. 1ad30 1ad90 1ad150 1ad210 1ad270 1ad330

count_steps=: 3 :0
 position=. +/(". ::])y
 h=. ne,n,nw,sw,s,se
 path=. 0j0
 p=. 0$<''
 while. 0.2<|position-{:path do.
  i=. (=<./)|position-,h+/{:path
  path=.path,({:path)+h#~i
  p=. p,<i#DIRS
 end.
 (;~#)p
)


   count_steps se,sw,se,sw,sw
┌─┬───┬──────┬────┐
│3│┌─┐│┌──┬─┐│┌──┐│
│ ││s│││sw│s│││sw││
│ │└─┘│└──┴─┘│└──┘│
└─┴───┴──────┴────┘

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

Reply via email to