190k views
3 votes
Two grids are shown below. For each grid, the code below is intended to move the robot to the gray square. The program uses the procedure Arrived(), which evaluates to true if the robot is in the gray square, and false otherwise.

REPEAT UNTIL (Arrived())
{
IF (CAN_MOVE(right))
{
ROTATE_RIGHT()
}
ELSE
{
IF (CAN_MOVE(left))
{
ROTATE_LEFT()
}
}
IF (CAN_MOVE(forward))
{
MOVE_FORWARD()
}
}
Repair the code so that the robot will make it to the gray square no matter which of the two grids it choses.

Two grids are shown below. For each grid, the code below is intended to move the robot-example-1
User Vojo
by
7.0k points

1 Answer

4 votes

Answer:

switch the IF statements

Step-by-step explanation:

if you allow the robot to check for space on the left first, it will run through both mazes correctly

User Viktor Arsanov
by
7.2k points