Simple question on grid I should be able to figure this out, but my brain isn't cooperating with me. Say I have a grid of 5x5, with each cell in the grid numbered from 0-24, going from left to right. Given a cell number such as 17, how do I determine that cell's x and y coordinates? I've been able to do it vice versa, where if given the coordinates I can calculate cell number:
$Cell number=x+y*width$
(The x and y coordinates represent the upper left point of each cell)
But now I want the opposite. Any ideas?
 A: Imagine you are writing the number in base (length or width). So here, we want to write the number in base 5. 17 can be written as $(32)_5$. But then this is all we need, as this says it's in the 3rd row, 2nd column.
The idea is that our 'index' goes up by 5 for every row we go down. Thus 1 will be the top left square, 1 + 5 = 6 will be the square below it, and so on. But this has a convenient notation base-5. 1 is written as $(01)_5$ in base 5, and 6 is written as $(11)_5$ in base 5 (I now let the subscript tell the base). In this way, we can see that the first digit tells which row we are in, and the second digit tells which column. So 11, which is written as $(21)_5$, is below $(11)_5 = 6$ and to the left of $(12)_5 = 7$.
This is actually the same process as the other answer, but it has the additional benefit of having all the uniqueness arguments that go along with bases. And I think the representation is very cute.
A: mohabitar, your equation for determining cell_number from x=column and y=row, works if you define the first row = 0 and the first column = 0 AND define your coordinate system such that y increases to the right and x increases down (or have cells 0-4 on the bottom row and work up).
Keeping with the reference system which you imply, you can extract x and y from cell_number as follows:
y = INT(cell_number/width)
x = MOD(cell_number/width)
where INT(z) returns the highest integer value which is equal to or smaller than z; and MOD(z) returns the modulus of z, which is defined as (z - INT(z)).
