Distance between two elements in an two dimensional array -
Distance between two elements in an two dimensional array -
i trying solve 8 puzzle game program. reason need find distance between 2 elements of 2 dimensional array. illustration
int[][] input = { { 8, 5, 1 }, { 7, 4, 3 }, { 2, 0, 6 } }; if want move '8' position [2][2], need 4 moves(move 2 cells horizontally , 2 vertically) distance [0][0] [2][2]. how can distance?
the distance [a1][b1] [a2][b2] abs(a1-a2)+abs(b1-b2).
arrays
Comments
Post a Comment