/* This is the efficient way to do this. */ reachable(X,Y) :- borders(X,Y). reachable(X,Y) :- reachable(X,Z), borders(Z,Y). borders(pa, md). borders(md,va).