read h w read {a..d} mapfile s n=1 Q=({a,b}-1) R=Q[--N] for((N=2;N;)){ for((q=R,p=R;(p|q)>=0&&z[p*64+q]++<4;t=u*u<2?1:u<0|v?0:2,Q[N++]=p+n*t,Q[N++]=q+m*t,t=n,n=m,m=-t)){ t=1${s[p]:q:1} u=t-1${s[p+n]:q+m:1} v=t-1${s[p+n+n]:q+m+m:1} } } NO echo ${_[z[c*64+d-65]]-YES}