A robot vacuum cleans a floor made of square tiles. Every tile has a position (x, y): x grows towards the east and y grows towards the north. The floor carries on as far as the robot likes in every direction — there are no walls.
The robot starts on tile (0, 0), facing north. Its facing is kept as a step tuple (dx, dy): the change one move forward makes to its position.
| facing | step tuple |
|---|---|
| north | (0, 1) |
| east | (1, 0) |
| south | (0, -1) |
| west | (-1, 0) |
It follows a string of one-letter commands:
| command | what the robot does |
|---|---|
F | moves forward one tile — unless that tile has furniture on it. Then it bumps, stays exactly where it is, and goes on to the next command. |
L | turns 90° to its left, without moving |
R | turns 90° to its right, without moving |
furniture is a list of (x, y) tiles the robot can never enter (a tile can be listed more than once). The start tile is always free.
Task: write vacuum_run(commands, furniture), returning a tuple (position, facing, cleaned):
position — the tile it finishes on,facing — its final step tuple,cleaned — how many different tiles it has stood on, including the start tile.Example
It moves north to (0, 1), turns to face east, moves to (1, 1), then bumps into the furniture at (2, 1) and stays put.