4
This question will be deleted soon, do not read/answer it
Introduction
Given one matrix A x A
and a number of movements N
.
You will need to walk like a spiral starting in (1; 1)
:
- right while possible, then
- down while possible, then
- left while possible, then
- up while possible, repeat until got
N
.
Challenge
You can only take as input the numbers A
and N
.
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.
Sample
For input (A = 8; N = 54
).
The output should be (5; 6
).
Another samples
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]
Restrictions
1 <= A <= 230
1 <= N <= (A2 OR the below higher number supported in your language).
And, if you want a generic formula.
1About restrictions: there are common languages that cannot handle 60 bits integers. Javascript for instance is limited to 53 bits for numbers stored as IEEE 754 64 bits floating point, or 32 bits for signed integers – edc65 – 2016-04-10T17:21:24.840
@edc65. You can use javascript, I will update – removed – 2016-04-10T17:28:38.967
1A=2^15 (2^30 cells) will run in reasonable time (seconds or minutes) and memory (gigabytes) if we trace through every cell. A=2^30 (2^60cells) will not. If your intention is to disallow naive algorithms you should state it in the question. Otherwise you should reduce the max size of the matrix – Level River St – 2016-04-10T17:30:34.097
1I've voted to close as it is not clear without further clarification whether the existing answer is valid or not: as stated by the poster, it is limited by memory to considerably less than A=2^30. Please clarify – Level River St – 2016-04-10T17:42:29.203
I just stated the size of the number, not about the memory, but I edited with a formula – removed – 2016-04-10T17:55:13.140
1@WashingtonGuedes But you haven't stated if explicit methods that are limited by memory are allowed or not – Luis Mendo – 2016-04-10T17:56:54.133
1@WashingtonGuedes also, we are discussing a hardware restriction, not a language restriction. – Level River St – 2016-04-10T18:02:37.897
Sorry, for all troubles, I tried deleting this question, but I can not because it has answers.. I will try to make it a community question then – removed – 2016-04-10T18:05:38.360
1No need for making it CW? Just clarify about the memory – Luis Mendo – 2016-04-10T18:47:19.793
Perhaps we can discuss this in chat: https://chat.stackexchange.com/rooms/240/the-nineteenth-byte
– Sherlock9 – 2016-04-10T19:12:19.7001Really there's no need to delete. It's a good question and I upvoted it. No "trouble" caused. The fairest thing to do (as you already have an answer) would be to reduce the max value of A which would let naive solutions work (such as 2^12) or say that the solution should work in theory notwithstanding memory and time constraints. However if you decide to rule that A=2^30 is required, @LuisMendo said he would delete or revise his answer. The purpose of putting on hold is to ensure more answers like Luis's don't come piling in till your intention is clarified. – Level River St – 2016-04-10T21:10:03.270
Another thing you can do is have a main codegolf competition admitting naive solutions, but offer a bounty on the side for the most efficient/elegant algorithm, if that's what you were hoping to see.. An advantage of this is that bounties can be awarded under subjective criteria, whereas the main competition must be objective. – Level River St – 2016-04-10T21:10:58.790