1. ## Spiral Number Matrices

Hello all, I would like to enquire what is the relationship between spiral number matrices like these :

n=3
1 2 3
8 9 4
7 6 5
n=7
1 2 3 4 5 6 7
24 25 26 27 28 29 8
23 40 41 42 43 30 9
22 39 48 49 44 31 10
21 38 47 46 45 32 11
20 37 36 35 34 33 12
19 18 17 16 15 14 13
I do know that there are a lot of solutions for such matrices on the web, but most of them are in C++ and just codes. What I would like to ask is whether it is actually possible to derive a general solution for every line? I came up with a few but as the number grew bigger the general solutions became wrong.

Oh, and also, is it actually possible to solve this matrix without using arrays at all?

Thanks

2. Hey, I can use google too....

[maths] number spiral matrix - Fanatic Networks

Perhaps you haven't come across this yet
How To Ask Questions The Smart Way

3. Originally Posted by Salem
Hey, I can use google too....

[maths] number spiral matrix - Fanatic Networks

Perhaps you haven't come across this yet
How To Ask Questions The Smart Way
sorry but I do not get you

Originally Posted by Char*Pntr
I did. and a couple others with different matrixes and they all seemed to use different approaches, so I thought there should be different ways for different types of such matrixes. and i only have minimal c programming knowledge of syntax which basically only consists of if, else, for , while ,etc without arrays and the rest

4. If a person can solve this, and they can enumerate the steps they took to solve it, then of course, a computer program could be written to solve it.

This problem isn't a cinch, but it's not OMG hard, either.

If you want to print it up, without using any data structure (like a matrix), to help out, it adds another layer of difficulty to the problem. Not impossible, but unless you're REALLY into spiral matrices for some reason, not worth the bother.

5. I don't see what the problem is. You can fill a matrix like that by simply traveling around it as the spiral does... I doubt any filling algorithm that does so row-by-row would be any faster.

6. I believe the problem is that (if you follow the links), spiral matrices could go in several different ways:

from the outside inward, top to bottom clockwise
from the outside inward, top to bottom, counter clockwise
from the outside inward, bottom to top, clockwise
...
from the inside outward, clockwise, starting at 12 o'clock position
from the inside outward, clockwise, starting at 3 o'clock position

etc.

And if that's the question, then no, I don't believe there is any algorithm to solve for all these different patterns - but there could be one made, of course. Think of a function to find the next square, and you're just passing it more parameters.

It would help if you were rather obsessive-compulsive to do this, for sure.

I believe the problem is that (if you follow the links), spiral matrices could go in several different ways:

from the outside inward, top to bottom clockwise
from the outside inward, top to bottom, counter clockwise
from the outside inward, bottom to top, clockwise
...
from the inside outward, clockwise, starting at 12 o'clock position
from the inside outward, clockwise, starting at 3 o'clock position

etc.
Yes. That was what I meant.

I don't see what the problem is. You can fill a matrix like that by simply traveling around it as the spiral does... I doubt any filling algorithm that does so row-by-row would be any faster.
How can I do that if I can only print row by row? (with only loops like if else , for, while)

8. Because if you know the dimensions of the array, and you know the type of spiral, and the direction of the spiral, and the starting point of the spiral, and etc., then you can actually figure out all the values to be put in the spiral matrix.

You have to take a big step "back" from normal element by element type thinking - but it can all be figured out with simple arithmetic, once you get your head wrapped around the equations.

No, I don't know them, but I can "smell 'em", cooking nearby.