Draw the path of the robot through the grid below if the following program is executed (the robot starts in the square marked by the ↑ facing in the direction of the arrow) - AQA - GCSE Computer Science - Question 9 - 2021 - Paper 1
Question 9
Draw the path of the robot through the grid below if the following program is executed (the robot starts in the square marked by the ↑ facing in the direction of the... show full transcript
Worked Solution & Example Answer:Draw the path of the robot through the grid below if the following program is executed (the robot starts in the square marked by the ↑ facing in the direction of the arrow) - AQA - GCSE Computer Science - Question 9 - 2021 - Paper 1
Step 1
1. Draw the path of the robot through the grid below if the following program is executed (the robot starts in the square marked by the ↑ facing in the direction of the arrow).
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The robot starts at position (2,3) facing up. Following the commands:
Forward(2): Moves to (0,3) [Square A].
TurnLeft(): Now facing left (West).
Forward(1): Moves to (0,2) [Square B].
TurnRight(): Now facing up (North).
Forward(1): Moves to (0,1) [Square C].
The path is drawn through squares A, B, and C.
Step 2
2. Draw the path of the robot through the grid below if the following program is executed (the robot starts in the square marked by the ↑ facing in the direction of the arrow). If a square is black then it contains an object.
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
In this scenario, the robot starts at position (2,3):
ObjectAhead(): The square (1,3) is empty, so the robot moves ahead.
TurnLeft(): Now facing left (West).
In the next iteration, ObjectAhead(): Square (1,3) is checked, robot turns left if found. As it is empty, it checks again to turn right and left subsequently.
It will continue until the path downwards is reached getting stuck at the black squares at positions (1,3) and (2,2).
Final movement goes down to (2,1) and then ends up at (2,0).