I am trying to calculate valid neighbour of a node
Array contains elements like [2,8,3,0,1,4,7,6,5]
Matrix:
2 8 3
0 1 4
7 6 5
It's similar to 8 puzzle logic. In the above matrix, i can swap 0 with 2 or 1 or 7. i tried with -1,+1,-3,+3. But 0 can't be swapped with 3. so i can't use -1 or +1. Also i need to update the position in array. What is the logic to achieve this.