Followers 0

# Need help with multidimentional array calculations

## 1 post in this topic

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.
0

##### Share on other sites

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.

0

## Create an account

Register a new account