views:

109

answers:

1

Hi

I have two 3x3 matrices. One representing the actual state and the other in a "current" state.

Actual state -> 1,2,3
                5,7,6,
                9,8,x

Current state1 -> 3,1,2
                  x,6,7
                  8,9,4

I need to bring the current state matrix to the original state by doing only swaps of element x and its adjacent element in horizontal or vertical direction.(diagonal is not allowed).

E.g. Current state 2 can be x,1,2  or 3,1,2 
                            3,6,7     6,x,7  
                            8,9,4     8,9,4

I can solve it till it reaches this state

current state n -> 1,2,3
                   5,7,6
                   8,9,x

I am clueless how to proceed to the original state after this, that is swapping two elements. Could you help me here?

Thanks

+4  A: 
Paul Wicks
Thanks a lot. that helped