Question: The PR 2 0 0 4 is a robot that automatically gathers toys and other items scattered in a tiled hallway. A tiled hallway has
The PR is a robot that automatically gathers toys and other items scattered in a tiled hallway. A tiled hallway has a wall at each end and consists of a single row of tiles, each with some number of items to be gathered.
The PR robot is initialized with a starting position and an array that contains the number of items on each tile. Initially the robot is facing right, meaning that it is facing toward highernumbered tiles.
The PR robot makes a sequence of moves until there are no items remaining on any tile. A move is defined as follows.
If there are any items on the current tile, then one item is removed.
If there are more items on the current tile, then the robot remains on the current tile facing the same direction.
If there are no more items on the current tile
if the robot can move forward, it advances to the next tile in the direction that it is facing;
otherwise, if the robot cannot move forward, it reverses direction and does not change position.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
