Sorry if this is a dumb question but I couldn't figure out the math formula.
I need to map number 1 to 9 to a 2D array/matrix with the position numbers like this:
123
456
789
So 1 -> M[0][0], 2 -> M[0][1] and so on.
Then what if the positions are labelled like this? The indices start from 0, not from 1.
012
345
678
The formula needs to work for larger matrix size input: 4x4, 4x5, 3x6, etc.
I'm completely lost.
I found some answers about Map a 2D array onto a 1D array but they're not quite what I'm looking for. I feel like I should be able to build on top of that but I couldn't figure it out.