Robot Turtles
InterviewTime limit1sMemory limit1024 MB
Find the shortest F, R, L, X program that moves the turtle from the bottom-left corner to the diamond on an 8x8 board with rock and ice castles.
- Level
Medium5 of 10
- Topics
- BFS, Simulation, Implementation
- Solved
- No attempts yet
Problem

Robot Turtles is one of Theta's favorite games. In this game, kindergarteners learn to "code" by writing programs that move a turtle from a starting field to a diamond. Robot Turtles is reportedly the most successful game funded by the Kickstarter incubator.
Players write a program made of "instructions" that brings a turtle from a starting location to a goal (a diamond). An adult then "executes" the program by moving the turtle according to the instructions.
Robot Turtles is played on an board. One turtle, marked with the letter T, always starts at the bottom-left field, facing right. The board contains empty squares (marked .), rock castles (C), and ice castles (I). The diamond is marked D. The turtle may move only onto empty squares and the square with the diamond.
A turtle program uses 4 instructions, each marked by a single letter.
FThe turtle moves one field forward in the direction it faces. If the turtle faces a castle or the border of the board, a program error occurs.RThe turtle turns 90 degrees to the right. It stays on the same field.LThe turtle turns 90 degrees to the left. It stays on the same field.XThe turtle fires a laser in the direction it faces. If the square it faces contains an ice castle, the ice castle melts and the square becomes empty. Otherwise, a program error occurs. The turtle does not move or change direction. Firing at an empty square, a rock castle, or outside the board is a program error.
Input
The input consists of 8 lines representing the board, with each line representing one row. The turtle always starts at the bottom-left. There is exactly 1 diamond. There are no more than 10 ice castles.
Output
Output the shortest valid turtle program whose execution (without program error) brings the turtle from the starting location to the diamond. If several programs have the same shortest length, you may output any of them.
Output no solution if the turtle cannot reach the diamond.