DWITE Online Computer Programming Contest

Robot Vacuum Prototype

October 2010
Problem 2

How hard can it possibly be to put together a robot vacuum? Some gears, some motors, and it can all be controlled by an iPhone. Easy, done! Now, to test if this thing actually works... You find a narrow hallway to safety run experiments in; it looks something like this:

.*...

There are 5 spaces, marked by periods. Your robot, marked by an asterisk, starts out somewhere in this hallway, and can move left or right. Once it reaches either end, further attempts to move in that direction keep it in the same spot.

The input file DATA2.txt will contain 5 sets of input. The first line will be a map, followed by 5 lines of directions – either L to move left or R to move right.

The output file OUT2.txt will contain 5 lines, a map of the hallway with the final position of the robot after executing the instructions.

Sample Input (first 2 shown):
*....
R
R
R
R
L
.*...
L
L
L
L
L
Sample Output (first 2 shown):
...*.
*....