The following program moves a robot in a grid of squares. The initial position and direction of the robot is shown below. Click on the grid to move the robot to the final position after the program is run. You must click within the box to rotate the robot to the correct final direction (click near the top of the box to rotate up, etc...) Feel free to move the robot along as you follow the code.
The following
PROCEDURE DoSomething(a)
{
MOVE_FORWARD()
if( a > 2 )
{
MOVE_FORWARD()
}
else
{
if( a = 3 )
{
MOVE_FORWARD()
}
}
MOVE_FORWARD()
}
i ⬅ 3
ROTATE_RIGHT()
REPEAT 2 TIMES
{
DoSomething(i)
MOVE_FORWARD()
ROTATE_RIGHT()
i ⬅ i - 1
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps