2

Just like the title I want to ask about formula for $n \times n$ spiral matrix. In particular, I want to know if there's a formula for a given entry in the matrix, without computing the full matrix.

Here is an example of the kind of matrix I'm talking about: $$\left[\begin{matrix} 1 & 2& 3& 4& 5& 6 \\ 20& 21& 22& 23& 24& 7 \\ 19& 32& 33& 34& 25& 8 \\ 18& 31& 36& 35& 26& 9 \\ 17& 30& 29& 28& 27& 10 \\ 16& 15& 14& 13& 12& 11 \end{matrix}\right]$$

pjs36
  • 17,979
  • 1
    google is your friend : https://www.google.pl/search?q=spiral+matrix&oq=spiral+matrix&aqs=chrome..69i57j0l5.4176j0j7&client=ubuntu&sourceid=chrome&ie=UTF-8 – Adam Apr 06 '18 at 16:27
  • 1
    yeah I've search that term before but that's not what I mean I want to know what the number by just knowing the coordinate – Thuận Nguyễn Apr 06 '18 at 16:31
  • Hint: recursive with each time taking the inner $n-1$ matrix block; for each layer you go in you add $4n-4$, so something like this:

    if (i > 1, k > 1) return (4n-4) + degree(i-1, k-1, minor(n-1)) else return ...

    – Rab Apr 06 '18 at 16:50
  • i'll leave the else part for you to figure out. – Rab Apr 06 '18 at 16:50
  • @ThuậnNguyễn I tried to clarify what I think you're asking, based on the comments (since you've gotten two comments about how one could programmatically create such a matrix, but that doesn't appear to be what you're interested in). Feel free to roll back my edit, to your original phrasing, or revise further. – pjs36 Apr 06 '18 at 16:54

0 Answers0