# Reply to comment

## Mad robot: Solution

A mad robot sets off towards the North East on a journey from the point (0,0) in a coordinate system. It travels in stages by moving forward and then rotating on the spot. It follows these pseudo-code instructions:

SUB JOURNEY

DISTANCE = 1000

WHILE (DISTANCE > 0.001)

MOVE DISTANCE

STOP

ROTATE(90, DEGREES, CLOCKWISE)

DISTANCE = DISTANCE / 2

END WHILE

EXPLODE

END SUB

Where does the robot explode?

### Solution

First we find the number of forward turns, noting that the WHILE(DISTANCE > 0.001) condition is evaluated after each halving.

The forward motion, if it occurs, following the th turn will be of distance . This will occur for each for which

Taking logs gives

Rearranging gives

This first becomes invalid after 20 turns. Thus, the path of the robot is determined by 20 motions. The directions that the robot travels in these 20 motions are alternately NE, SE, SW, NW, .... Since there are 20 motions in total there are 5 motions in each of these directions.

Let be the total distance travelled NE. Then

The NE motion contributes a component travelled in the direction and the same component travelled in the direction. By Pythagorasâ€™ theorem we have

so

Note that the distance SE will be half of T, since each motion is half the length of the preceding NE motion. Similarly, the total distance SW will be one quarter of ; total distance NW will be one eighth of . Each of these motions contributes the same component in the -direction as in the -direction. The NE direction counts positively towards both and directions, the SE direction counts positively in the direction and negatively in the direction, SW counts negatively in both and directions and NW counts negatively in the and positively in the direction. The final coordinates are therefore

*This problem comes from our sister site NRICH, which is packed with challenges, activities and articles for maths learners and teachers.*