The robot can only move east or north (if see it in reverse S or W). You can't snake (if you go away you never come back). |
That actually makes the problem much more tractable.
Let N=0 and E=1, then you could describe a path from beginning to the end with just a string of bits.
Let a subpath be any string of these bits like 0110, etc...
A subpath may have the following characteristics: either it can reach the entrance or it can't, either it can reach the exit or it can't - the possibilities can be described in 2 bits: 00, 01, 11, 10 - we care about the 11's (can reach entrance AND can reach exit) and don't care about the rest.
These characteristics are transferrable. Say you have a subpath A which can reach the entrance and subpath B which is reachable from subpath A. Then subpath B can also reach the entrance.
Broken down in this way, the entire problem could actually be parallelized and run on multicores/multi-processors separately and then recombined.
-------------------------------------------------
Another, simpler way, to look at this is, if the exit is m squares to the North and n squares to the East, the robot
must use up m North moves and n East moves.
If it does, it surely has reached the exit.
If it reaches a point where it cannot do any more North moves or East moves, it has reached a dead-end.