Example
Input: 10
Output x: [0, 0, 1, 3, 5, 7, 7, 6, 4, 0, -4, -7]
Output y: [0, 1, 2, 2, 1, -1, -4, -7, -10, -10, -9, -6]
Output x: [0, 0, 1, 3, 5, 7, 7, 6, 4, 0, -4, -7]
Output y: [0, 1, 2, 2, 1, -1, -4, -7, -10, -10, -9, -6]
A Babylonian spiral is constructed by starting with a zero vector at the origin of a Cartesian grid and progressively concatenating the next longest vector with integer components. So the $i$th vector has integer components $(x_i, y_i)$ satisfying $x_i^2 + y_i^2 = n_i^2 > n_{i-1}^2$ where $x_i$, $y_i$ and $n_i$ are non-negative integers. The direction of the new vector is chosen such that it minimizes the clockwise angular separation from the previous one.
Starting with the vectors $(x_0, y_0) = (0, 0)$ and $(x_1, y_1) = (0, 1)$ find the $x$ and $y$ coordinates of the Babylonian spiral after $N$ steps.
Input: Number of steps $N$.
Output: The $x$ and $y$ coordinates as lists.
Difficulty | Timesink | ||
---|---|---|---|
Function | babylonian_spiral(n_steps) |
You must be logged in to view your submissions.
Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able see a discussion thread below. Would be nice if you don't post solutions in there but if you do then please organize and document your code well so others can learn from it.