Problem 44376. The sliding puzzle: 3D
This is an extension of problem 42842. In this case, the puzzle is three-dimensional and is of size 3x3x3. Of the 27 positions in the puzzle, 26 are occupied by cubes numbered 1 thru 26, while the remaining position is empty. You can slide an adjacent cube into the empty position, similarly to sliding an adjacent tile into the empty position in the 15 puzzle.
In this case, for simplicity, the puzzle is represented by a vectorized form of the puzzle, such that the 3D form of the puzzle can be obtained by reshape(p,[3 3 3]). Therefore, a solved cube shall look like this:
Given the initial state vector, p, return a vector, m, comprising a sequence of integers, representing the linear indices of the cubes you wish to slide, in turn, into the empty position, in order to solve the puzzle.
As before, 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.
Solution CommentsShow comments
Problem Recent Solvers49