This classic puzzle can be found on many different websites (Spoilers!). It seems to originate from a Microsoft interview question. This is an interactive version of the puzzle where you can immediately try your ideas.
Two robots are to be parachuted onto random locations on an infinite line. When they land, their parachutes detach and remain where they are. The robots may be programmed from the following instruction set:
left | Go left one unit |
right | Go right one unit |
skipNext | Skip next instruction if there is a parachute here |
goto label | Go to label |
Each of these instruction can be prepended by an optional label (label: instruction
).
Your goal is to program the robots to meet (collide). They both run the same code.
A game by David Peter. Source code on Github.