Definition
The infinite spiral used in this question has 0
on the position (0,0)
, and continues like this:
16-15-14-13-12
| |
17 4--3--2 11
| | | |
18 5 0--1 10
| | |
19 6--7--8--9
|
20--21...
It is to be interpreted as a Cartesian plane.
For example, 1
is on the position (1,0)
, and 2
is on the position (1,1)
.
Task
Given a non-negative integer, output its position in the spiral.
Specs
- Your spiral can start with
1
instead of0
. If it starts with1
, please indicate so in your answer. - Output the two numbers in any sensible format.
Testcases
The testcases are 0-indexed but you can use 1-indexed as well.
input output
0 (0,0)
1 (1,0)
2 (1,1)
3 (0,1)
4 (-1,1)
5 (-1,0)
6 (-1,-1)
7 (0,-1)
8 (1,-1)
9 (2,-1)
100 (-5,5)