I heard about this problem often being used by companies to screen and test potential candidates for a technical interview, and I thought it would be fun to implement a live editor playground where you'd be able to test your solution and visualize what's happening. It's quite a brain teaser!
Demo
Here it is: https://petarjs.github.io/robot/
Note: the demo comes loaded with the solution code, but you can try to program them yourself too.
The Problem
The problem is an interesting one. You are to program two imaginary robots, that will execute the same code. They are standing on a line and can move left or right. We don't know their starting positions, but below each one is an oil mark that marks their starting position. The goal is to program the robots to make them collide. Remember, both of them execute the same commands!
Commands
The available commands are:
- L - Go left
- R - Go right
- S - Skip the next command if an oil mark is below the robot
- G label - go to a label
StackOverflow
You can see a discussion about this and a better description of the rules here - https://stackoverflow.com/questions/25596473/two-robots-on-a-line.