I have a diamond shaped map that is deserialized/represented as follows:

` j 0 1 2 3 4 5 6 7 i 0 * * * 0 1 * * * 1 * * 2 3 4 5 * * 2 * 6 7 8 9 10 11 * 3 12 13 14 15 16 17 18 19 4 20 21 22 23 24 25 26 27 5 * 28 29 30 31 32 33 * 6 * * 34 35 36 37 * * 7 * * * 38 39 * * * `

I want to convert the tile number, to its coordinates (i, j) and back. I have managed to convert a coordinate to its tile number like so:

`Given a map width and height n: if(i< (n/2): number = i*(i+1) + j else: number = (2*((n/2)*((n/2)+1))) - ((n-i)*(n-i+1))) + j So: (0, 3) -> 0; (6, 2) -> 34; `

However, I cannot figure out to go back to the coordinates from the tile numbers, because I have trouble with distilling the i parameter from the tile number.

I have tried googling with terms like "diamond shaped map tile numbers coordinates convert", but no luck.

Can someone point me in the right direction?