Skip to main content
4 of 10
added 5 characters in body
Chas Brown
  • 9.8k
  • 1
  • 13
  • 39

Python 2, 236 235 bytes

def f((x,y),G,M,U=[]):
 R=1-(len(M[0])-1>x>0<y<len(M)-1);H=[(u+cmp(x,u),v+cmp(y,v)*(u==x))for u,v in G];d,e=0,1
 for _ in' '*4*(R<1and(x,y)not in H):J=(z,w)=x+d,y+e;d,e=-e,d;R|=M[w][z]and(not J in U)and f(J,H,M,U+[J]);U=U+[J]
 return R

Try it online!

As input, takes a tuple (x,y) as jimmy's initial position, a list G == [(g1x,g1y), ...] of initial ghost positions, and a list of lists M which is the 2-dimensional binary matrix where cells are 0 if they contain "an object" (i.e., #) and 1 otherwise.

Returns 1 for truthy, 0 for falsey.

Loosely speaking, the idea here is that we're going to depth-first recurse over left, right, top, down to seek a border cell.

Chas Brown
  • 9.8k
  • 1
  • 13
  • 39