The PR2004 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 PR2004 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 higher-numbered tiles.
The PR2004 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.