# Iterating 1D array and getting 2D tile position

I know I'm missing something very obvious here, but I have a 1D array that contains integers.I have a map that is 30 x 30 and the center coordinate is 0,0 (This is actually 3D, but I'm essentially removing the Y-axis). Because of this offset, my loop is from -15 to 14, rather than 0 to 29. Is this incorrect?

I'd like to iterate through the array and if the integer is "1", then I'd like to call AddSphere(x,y,z) with the correct x and z values. How would I get the correct values for x and z? The file is designed to be read left to right rather than left to right, right to left, left to right etc... (although if that's a better approach, I can just change the data to match that style).

One possible way is to split the integer into two values between 0 and 29 (this is done using integer division and modulus) then offset them by -15:

for (int n = 0; n < 30 * 30; ++n)
{
if (Array[n] == 1)
{
int x = n % 30 - 15;
int y = 0;
int z = n / 30 - 15;


Note that -15..14 is asymmetrical. If you want (0,0) to be at the exact centre of your map, you need an odd value instead of 30.