P
Paul A.
Hello,
I would like to converte an index (of a flatten array) to a
multi-dimensions coordinates (of the multi-dimensions version of the
previous flatten array).
Example:
Considering the following 2 dimensions array (3x3):
[ [ -, -, - ],
[ *, -, - ],
[ -, -, - ] ]
We can see that, the coordinates of the checked case is [0, 1].
Now, if we flat this array, it looks like:
[ -, -, -, *, -, -, -, -, - ]
Here, we can see the coordinate (or the index) of the checked case is 3.
But how can we do the opposite? I mean, a method looking like:
index_to_coordinates([3, 3], 3) # => [0, 1]
Thanks!
I would like to converte an index (of a flatten array) to a
multi-dimensions coordinates (of the multi-dimensions version of the
previous flatten array).
Example:
Considering the following 2 dimensions array (3x3):
[ [ -, -, - ],
[ *, -, - ],
[ -, -, - ] ]
We can see that, the coordinates of the checked case is [0, 1].
Now, if we flat this array, it looks like:
[ -, -, -, *, -, -, -, -, - ]
Here, we can see the coordinate (or the index) of the checked case is 3.
But how can we do the opposite? I mean, a method looking like:
index_to_coordinates([3, 3], 3) # => [0, 1]
Thanks!