#224EasySimulation· Repeating Instruction Cycle
Robot Patrol Loop
Input format
`instructions`: a string made of the characters G, L and R.
Output format
A boolean.
Examples
Input: instructions = "GGLLGG"
Output: true
The robot goes two cells north, turns around and walks two cells back to the origin, now facing south. A second pass retraces the same line and returns it to the origin facing north again, so it never leaves a small area.
Input: instructions = "GG"
Output: false
It walks north forever, so it is not contained.
Input: instructions = "GL"
Output: true
One step then a left turn: after four repetitions the robot walks a square and is back at the origin.
Constraints
- 1 <= instructions.length <= 100
- instructions[i] is one of G, L, R.
- #simulation
- #math
- #geometry
- #strings