How to solve ANY slide puzzle regardless of its size 15


After seeing many people giving up while playing slide puzzles in the best free online puzzle site, I decided to write this fool proof fully illustrated guide to solve any slide puzzle (3×3, 4×4, 5×5, …).

I came to the solution while developing the website im-a-puzzle.com and observing that the A* like algorithms take too long to solve puzzles. The nice thing about the solution is that it is so simple that even an human being can execute it 🙂

Divide and conquer

The beauty of the solution proposed here is that it is applicable to any puzzle size: 3×3, 4×4, 5×5, etc. The trick is to solve the edges first so that a 5×5 puzzle becomes a 4×4 and then a 3×3. This technique is also known as divide and conquer, where a complex problem is broke down into sub-problems, until these become simple enough to be solved directly.

The algorithm

Steps to solve any slide puzzle
The algorithm consist of following steps:

  • Solve the top edge (step 1 below)
  • Solve the left edge (step 2 below)
  • Repeat steps 1 and 2 until the puzzle size is decreased to 3×3
  • Solve the top edge only (step 1 below)
  • Solve the remaining 3×2 puzzle (step 4 below)

To move a piece to any position the easiest way is to:

  • Put the blank square at the target position
  • Move your piece in the target direction by moving all the pieces one square forward
  • Put the blank square ahead of your piece again by revolving the pieces around your target piece
  • Repeat steps 2 and 3 until your piece reaches its target

You are going to find many animated examples of these steps in the guide below. As the algorithm consist of solving the edges one-by-one, once an edge is solved it is consider as “frozen” and you should no longer touch it. That means that when you are revolving the pieces around your target piece you should never breach the “frozen” area.

The steps

STEP 1 – Solve the upper edge

Position all the top pieces from left to right:

1.1 Move the 1st piece to the top left corner.

Click on the image to see the animation

1.2 Move the 2nd piece to the top edge just close to the 1st piece

Click on the image to see the animation

1.3 If required move the 3rd, 4th pieces and so on until there is only 2 missing (applicable for puzzles bigger than 4×4)

1.4 Make sure that the last piece of the row is not on the top row itself. If yes, move it out! (Anywhere far away from it)

1.5 Move the before last piece of the row to the top right corner (for a 3 columns puzzle, the 2nd piece, for a 4 columns puzzle the 3rd piece, etc.).


Click on the image to see the animation

1.6 Position the last piece of the row just below it (right edge, 2nd position from the top)

Click on the image to see the animation

1.7 Move the before last piece to its correct place and the last piece just behind it

Click on the image to see the animation

If you are solving a 3×3 puzzle jump to step 4

STEP 2 – Solve the left edge

Position all the left pieces from top to bottom. Please note that the first piece is already be on its correct position:

2.1 Move the 2nd piece of the column just below the 1st piece

Click on the image to see the animation

2.2 If required move the 3rd, 4th pieces and so on until there is only 2 missing (applicable for puzzles bigger than 4×4)

2.3 Make sure that the last piece of the column is not on the left column itself. If yes, move it out! (Anywhere far away from it)

2.4 Move the before last piece of the column to the bottom left corner (for a 3 columns puzzle, the 4th piece, for a 4 columns puzzle the 9th piece, etc.).

Click on the image to see the animation

2.5 Move the last piece of the column just to the right of it (bottom edge, 2nd position from the left).

Click on the image to see the animation

2.6 Move the before last piece to its correct place and the last piece just behind it.

Click on the image to see the animation

STEP 3 – Repeat steps 1 and 2

Consider the top and left edges as frozen (you are not allowed to touch these pieces anymore!). Go back to step 1 assuming that you are now solving a smaller puzzle. Examples:

  • If you froze the top and left edges of a 4×4 puzzle, you will now have to solve a 3×3 puzzle.
  • If you froze the top and left edges of a 5×5 puzzle, you will now have to solve a 4×4 puzzle.
  • And so on…

If you are solving a 3×3 puzzle you will execute step 1 only and jump to step 4

STEP 4 – Solve the 3×2 puzzle

If you got here than there are only 5 pieces left to position (plus the blank piece). From here on, there is no all-in-one solution and you have to find the solution out yourself. But at the same time there are not many possible combinations.

Click on the image to see the animation

You will notice that there are only 4 basic movements possible: turning the first square clockwise or counterclockwise or turning the second square clockwise or counterclockwise. You will have to find your way and use them over and over until the 3×2 puzzle is solved. You can try to solve the remaining left edge of the 3×2 puzzle but that’s not strictly necessary. The worst case scenario happens when the numbers are displayed in the opposite order or when they are in the right order but in the wrong row.

The good thing is that this amazing puzzle maker only generates solvable puzzles. You do not have to be afraid that your puzzle will not have a solution.

If you have any suggestions or comments to the current algorithm feel free to write them here below.

Have fun!


Leave a comment

Your email address will not be published. Required fields are marked *

15 thoughts on “How to solve ANY slide puzzle regardless of its size

  • Mary Hellgren

    I have a 10 X 10 done except the 81 and 91 are transposed< (81 is in column 1 row 10 and 91 is in col 1 row 9) and I am stuck. I don't see a solution to these in your solver. Do you have one?

  • Sanghmitra

    Please make 5*5 slide puzzle. I always stuck in
    Last step. My all slide solves but in last always 24 first
    Before 23. Means 21 22 24 23.

    • Bruno Marotta Post author

      You need to put the 21 with the sixteen

      Prepare
      1 2 3 4 5
      6 7 8 9 10
      11 12 13 14 15
      xx xx xx xx
      16 21 xx xx xx

      Move 16 and 21

      1 2 3 4 5
      6 7 8 9 10
      11 12 13 14 15
      16 xx xx xx
      21 xx xx xx xx

    • Bruno Marotta Post author

      Hi Ralf,

      you’re absolutely right. This article was written many years ago, and I misused the words edge and corner. I’ve corrected it now. Could you please check again?

      Thanks a lot!

  • Dfly

    I always seem to have the problem that all solvers always put the empty hole bottom right. the one I am trying to solve has it at the top right.
    for some reason I cannot understand what I must do to get it to work. It should be an easy 3×3, but it is not for me. The setup is:
    1 2 3 where the 3 is the blank hole, when the puzzle is solved. My current figuration is 2 1 3
    4 5 6 5 4 6
    7 8 9 7 8 9
    I was trying to do bottom line first due to 3 being the empty, but can’t quite get the rest right.
    Can you help?

    • Bruno Marotta Post author

      Hi Isme,

      From your text is not easy to understand what is the current configuration.

      But if the hole is in the top right, you should solve the bottom line 7 8 9 (as you did) then the left column 1 4 7 (which is already in place).
      To solve the left column, you can put the number 1 on the position 4 and the number 4 on position 5. Then you just need to move the remaining numbers until the fall into place

      See how it could be doe (omitting 7 8 9 as they shouldn’t be touched):

      2 1 _
      5 4 6

      2 1 6
      5 4 _

      2 1 6
      5 _ 4

      2 _ 6
      5 1 4

      _ 2 6
      5 1 4

      5 2 6
      _ 1 4

      5 2 6
      1 _ 4

      5 2 6
      1 4 _

      From here you can figure it out yourself 🙂

      In case not:

      5 2 _
      1 4 6

      5 _ 2
      1 4 6

      _ 5 2
      1 4 6

      1 5 2
      _ 4 6

      1 5 2
      4 _ 6

      1 _ 2
      4 5 6

      1 2 _
      4 5 6