indexing - Trouble with a equation in Java -


i'm working on 15 puzzle game android school. sadly i've ran problem.

i need rewrite equation row , column instead of index. have @ code , se if guys can me out!

this takes row , column , return me corresponding index.

int index = 4 * (row - 1) + (column - 1); 

however, turn index row , column. know how sort of reverse equation return row , column 2 different ints.

thank, mikael

try this:

row = index / 4 + 1; column = (index % 4) + 1; 

note (and original formula) works if column < 5 (which is, of course, 15 puzzle).


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -