Jump to content

  • Log In with Google      Sign In   
  • Create Account

Need help with multidimentional array calculations


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Aluthreney   Members   -  Reputation: 256

Like
0Likes
Like

Posted 26 August 2013 - 07:18 AM

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.


Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5434

Like
0Likes
Like

Posted 26 August 2013 - 07:28 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS