Gamified challenge · Simulation
A robot starts at (0, 0) facing north on an endless floor. Its program is a string of G (step forward one square), L (turn 90° left on the spot) and R (turn 90° right on the spot). When it reaches the end of the program it starts again from the beginning, forever.
Write bounded(program) that returns true if the robot never leaves some circle around the start, and false if it drifts away without limit. Example: "GGLLGG" walks north 2, turns round and walks back, so it is true; "GG" walks north forever, so it is false. An empty program never moves: true.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google