Need help with multidimentional array calculations

Started by
0 comments, last by Paradigm Shifter 10 years, 8 months ago
I'm working on recreating the renowned Game of Life simulation and I'm currently having some problems with my math. To get to the point, I'm trying to calculate the column and row of a specific element within the array knowing only the size of the array as well as the last element of the array. Let me explain by listing the information:
Index
e - element in the array
x - column where e is situated
y - row where e is situated
X - Size of the array (columns)
Y - Size of the array (rows)
e = (y*X)+x <--- equation for finding an element knowing the column and row.
x = e-(y*X) <--- equation for finding the column of an element knowing the element and the row.
y = (e*x)/X <--- equation for finding the row of an element knowing the element and the column.
The array I'm working with is 8x6.
So I'm trying to find an algebraic expression that will allow me to find the column of element 9 knowing only the dimetions of the array and that the last element is 47.
P.S. If you have an answer I'd prefer if you'd point me in the right direction instead of saying it directly because I want to figure this out in order to understand it better.

Aluthreney -- the King of sheep.

Advertisement

You want the modulus operator %, a % b which returns the remainder when a / b (using integer division).

You do need to know the number of rows and columns though (which you do, 8x6), knowing the last element on its own is not sufficient since it could be 6x8, 8x6, 12x4, 3x16, etc.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

This topic is closed to new replies.

Advertisement