Jump to content
  • Advertisement
Sign in to follow this  

Need help with multidimentional array calculations

This topic is 2152 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!