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:
p = [1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;0]
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.
Example:
p = [0;2;3;1;5;6;4;7;9;10;11;12;13;17;14;16;8;18;19;20;21;22;23;15;25;26;24]
m = [4 7 8 17 14 15 24 27]
Solution Stats
Problem Comments
-
9 Comments
Show
6 older comments
Rafael S.T. Vieira
on 10 Jul 2020
Good problem. Tip: use the L1-norm or manhattan distance using the 3 indexes as a cost function.
Johanna Richter
on 17 Oct 2020
I am actually giving up :(
tried a lot......
邵俊淞2353280
on 2 Aug 2024
Too difficult
Solution Comments
Show commentsGroup

Number Manipulation IV
- 15 Problems
- 30 Finishers
- Pattern Sum
- Smallest n, for n! to have m trailing zero digits
- Still more miles to go before I sleep
- Convert from Base 10 to base 5
- Numbers on 7-segment
- Expand 10^n to Powers of 4
- Muphry's Law of MATLAB
- Lunar Arithmetic (Addition)
- Lunar Arithmetic (Multiplication)
- Permutation Via Multiplication
- The last non-zero digit of a factorial
- The number of trailing zero digit of a factorial
- Whole Number Concatenator
- Whole Number Un-Concatenator
- Smallest n, for n! to have m trailing zero digits
- Better Index Number
Problem Recent Solvers49
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!