JavaScript (ES6), 138 bytes
Expects (p)(q).
p=>q=>(X=2*(g=(q,h=o=[1],v=n=x=y=0)=>n-q|x-q[0]|y-q[1]?g(q,...o[o[[x-=h,y-=v]]=++n,[x-v,y+h]]?[h,v]:[v,-h]):x)(q),Y=2*y,g([X-g(p),Y-y]),n)
Arnauld
- 205.5k
- 21
- 187
- 670
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack ExchangeExpects (p)(q).
p=>q=>(X=2*(g=(q,h=o=[1],v=n=x=y=0)=>n-q|x-q[0]|y-q[1]?g(q,...o[o[[x-=h,y-=v]]=++n,[x-v,y+h]]?[h,v]:[v,-h]):x)(q),Y=2*y,g([X-g(p),Y-y]),n)