This is an algorithmic problem that I encountered in a programming contest. I am looking for a mathematical explanation/reason behind the solution.
The Problem is -
We have a robot initially stands at (0, 0) and faces north. The robot can receive one of the following three instructions:
"G": go straight 1 unit;
"L": turn 90 degrees to the left;
"R": turn 90 degress to the right.
The robot performs the instructions given in order, and repeats them forever.
Return true if and only if there exists a circle in the plane such that the robot never leaves the circle.
Example Testcase:
1)Input: "GGLLGG"
Output: true
2)Input: "GG"
Ouput :false
The solution says that
1)If the robot reaches the origin after completing the order, then answer will be true .This I was able to think(but still could not prove mathematically)
2)If after completing the order, it faces north then answer will be false.
3)Otherwise answer will be true.
Is the problem basically asking whether the movement of robot(ie completing the order once like "GGLLGG") is a preserved invariance in terms that robot will not move out of a circle at any state?

If the instruction sequence leaves the robot some distance from the origin, say at (x,y), and still facing the same way, then repeating the instructions will subsequently put it at (2x,2y), (3x,3y), (4x,4y), ... and so on. The distance to the origin will grow indefinitely, so it will exceed the radius of any circle you try to bound it in.
Suppose the instruction sequence leaves the robot at (x,y) but also turns it a quarter turn to the right. When it repeats the instructions three more times, it will essentially travel clockwise in a square. Although each side of the "square" will be a wiggly path, the end points of the four sequences form a square with the coordinates (x,y), (x+y,y-x), (y,-x), and (0,0). Further repetitions simply repeat that square. The distance to the origin is bounded by the number of steps the robot takes while doing that sequence four times, so the whole path can be bounded by a circle of that radius.
Suppose the instruction sequence leaves the robot at (x,y) but also turns it a quarter turn to the left. This is the same as the above, except that the robot goes anti-clockwise around the "square".
Suppose the instruction sequence leaves the robot at (x,y) but also turns it a half turn. In this case the next repetition already returns it to where it started. Again this is bounded, this time by the number of steps done in just two repetitions of the sequence.
The only remaining case is where the instruction sequence leaves the robot at the origin and still facing north. Now it is back to where it started after doing the sequence once, so the whole path is bounded by the number of steps in that single sequence.
To recap: