I’m currently working on a 15 puzzle game for Android for school. Sadly I’ve ran into a problem.
I need to rewrite this equation to get a row and column from it instead of a index. Have a look at the code and se if you guys can help me out!
This takes a row and column and return me a corresponding index.
int index = 4 * (row - 1) + (column - 1);
However, now I would like to turn a index into a row and column.
So does anyone know how to sort of reverse this equation to return a row and a column into two different ints.
Thank,
Mikael
Try this:
Note that this (and the original formula) only works if
column < 5(which it is, of course, for a 15 puzzle).