This question will be deleted soon, do not read/answer it
Given one matrix
A x A and a number of movements
You will need to walk like a spiral starting in
- right while possible, then
- down while possible, then
- left while possible, then
- up while possible, repeat until got
You can only take as input the numbers
You must output the final
(row; column) after walking
N steps in the conditions explained above. You can not invert the output order.
You can use indexes starting with zero as well. Just state it in your answer.
Program or function allowed.
This is code-golf, shortest answer in bytes wins.
For input (
A = 8; N = 54).
The output should be (
input: A=8, N=64 output: [5, 4]
input: A=15, N=14 output: [1, 14]
input: A=26, N=400 output: [22, 9]
input: A=1073741824, N=1152921504603393520 output: [536871276, 536869983]
1 <= A <= 230
1 <= N <= (A2 OR the below higher number supported in your language).
And, if you want a generic formula.