Cody

# Problem 42842. The sliding puzzle: 15

• Created by HH

If you are unfamiliar with the sliding puzzle, enter the command fifteen in your MATLAB command window (or search online, of course). In this problem you are tasked with solving the puzzle.

Given a scrambled classic 4-by-4 sliding puzzle, return a set of moves that solves it.

The puzzle is represented by a size [4 4] array, p, with integers from 1 to 15 representing the different tiles, and 0 representing the open slot. A single move is represented by an integer that is the linear index of the the tile you wish to slide into an adjacent open slot. A solution is represented by a row vector, m, of moves, the application of which results in a correctly arranged puzzle.

The solution does not have to be efficient. It must simply result in a correctly solved puzzle. Illegal moves, such as trying to slide a tile that is not adjacent to the open slot, will be ignored.

` p = [ 01 02 03 04;`
`       05 10 06 07;`
`       09 00 11 08;`
`       13 14 15 12]`
` m = [6 10 14 15 16]`

### Solution Stats

17.65% Correct | 82.35% Incorrect
Last Solution submitted on Oct 24, 2019