6
1
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 1instead 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)
 
  
  
  
  
  
 
1Some bigger testcases would be nice. – orlp – 2016-08-01T03:38:11.150
@orlp Done. – – – Leaky Nun – 2016-08-01T03:39:16.557
Can we print coordinates as a complex number? – orlp – 2016-08-01T03:54:33.447
@orlp As long as it matches the regex. – Leaky Nun – 2016-08-01T03:57:51.590
2I'm not sure how to interpret the regex requirement for return values. In some languages, the output of, e.g., a complex number, will depend on what function is called to print it. – Dennis – 2016-08-01T04:02:30.747
Related. – Martin Ender – 2016-08-01T07:26:26.393