Solvability of a sliding puzzle of size n*n

756 Views Asked by At

Hey guys according to this link right here: https://www.geeksforgeeks.org/check-instance-15-puzzle-solvable/ "If N is odd, then puzzle instance is solvable if number of inversions is even in the input state. If N is even, puzzle instance is solvable if the blank is on an even row counting from the bottom (second-last, fourth-last, etc.) and number of inversions is odd. the blank is on an odd row counting from the bottom (last, third-last, fifth-last, etc.) and number of inversions is even. For all other cases, the puzzle instance is not solvable." However, for the below sliding puzzle
0,1
3,2
we have 1 inversion, and N is even, and the "blank" is exactly "even" row counting from the bottom, but this puzzle is unsolvable to it's original state
0,1
2,3
can someone explain what's wrong?

1

There are 1 best solutions below

0
On

The trouble with referencing the "bottom" of the puzzle is that it all depends on your frame of reference. The website you use as a source for this question makes the assumption that the blank is, by default, in the lower-right corner. That is why they use "rows from the bottom" when referencing the position of the blank. In your scenario, the blank is in the default position. If the puzzle was rotated so the default position of the blank was the lower-right corner, it would look like

3,2
1,0 (blank)

Your unsolvable variant would therefore look like

2,3
1,0 (blank)

As you can see, the blank is in an odd row counting from the bottom, which means that an even number of inversions is required to successfully solve the puzzle. Your puzzle, with an odd number of inversions, is not solvable, and so fits the conditions perfectly.