Before we begin this week’s puzzle, we wanted to wish all of you guys good luck for the upcoming placement tests. The hiring season is in full swing and we gladly wish that you get placed in your dream firms and have all that this world has in store for you 🤞🏻
Now for this week’s crazy question :
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?
Try to solve this problem yourself before moving on to the solution below
.
.
.
.
.
.
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
.
.
😃 Over to you: Were you able to solve this?
👉 If you liked this post, don’t forget to leave a like ❤️. It helps more people discover this newsletter on Substack and tells us that you appreciate solving these weekly questions. The button is located towards the bottom of this email.
👉 If you love reading this newsletter, feel free to share it with friends!