If we take the natural numbers and roll them up counter clock-wise into a spiral we end up with the following infinite spiral:
....--57--56
|
36--35--34--33--32--31--30 55
| | |
37 16--15--14--13--12 29 54
| | | | |
38 17 4---3---2 11 28 53
| | | | | | |
39 18 5 0---1 10 27 52
| | | | | |
40 19 6---7---8---9 26 51
| | | |
41 20--21--22--23--24--25 50
| |
42--43--44--45--46--47--48--49
Given some number in that spiral your task is to determine its neighbours - meaning the element above, left, right and below it.
Example
If we have a look at 27
we can see that it has the following neighbours:
- above:
28
- left:
10
- right:
52
- below:
26
So the output would be: [28,10,52,26]
Rules
- Input will be a number \$n \geq 0\$ in any default I/O format
- Output will be a list/matrix/.. of that numbers' 4 neighbours in any (consistent!) order
- You may work with a spiral that starts with 1 instead of 0, however you should specify that in your answer
Examples
The output is in the format [above,left,right,below]
and uses a 0-based spiral:
0 -> [3,5,1,7]
1 -> [2,0,10,8]
2 -> [13,3,11,1]
3 -> [14,4,2,0]
6 -> [5,19,7,21]
16 -> [35,37,15,17]
25 -> [26,24,50,48]
27 -> [28,10,52,26]
73 -> [42,72,74,112]
101 -> [100,146,64,102]
2000 -> [1825,1999,2001,2183]
1000000 -> [1004003,1004005,999999,1000001]