Point $A$ starts from the origin and moves along a "spiral" as shown below. $A_i(x_i, y_i)$ represents the position of point $A$ after $i$-th move, with each move represented with a vector of magnitude 1. The question is very simple:
What is the simplest way to calculate $x_i,y_i$ as a function of $i$? For example, $x_{38}=-3$, $y_{38}=1$.
It's not too difficult to calculate this by using some computer code. My code follows a very simple logic: if the current position is $A_i$ the point will try to turn to the left if the square to the left has not yet been visited. If it is already visited, the point keeps current direction and moves one more step forward. You have just to count the number of moves, keep track of the current direction and visited fields. However, the code is terribly inefficient and becomes unusable for big values of $i$.
