The hardest eight-puzzle instances take 31 moves to solve

I’m sure this information is available elsewhere, but I couldn’t find it with a quick google search — the two hardest 8-puzzle instances are:

 8 6 7
 2 5 4
 3 . 1
 
 6 4 7
 8 5 .
 3 2 1

Both require at least 31 moves to solve. All other instances can be solved in 30 moves or less. (Found using breadth-first graph search, starting at the goal state). Somewhat interestingly, they are not obviously symmetric, but differ only in the locations of the even pieces.

6 Comments »

  1. Mati said,

    May 16, 2009 @ 3:27 pm

    But which is the final state for those puzzles?
    Cause there are two disconnected parts in the search space for this problem.
    Thx!

  2. Jason Wolfe said,

    May 17, 2009 @ 10:25 pm

    Good point. The post was referring to the standard version where the final state is:

    1 2 3
    4 5 6
    7 8 .

  3. mimighost said,

    April 4, 2011 @ 3:43 am

    I got your blog from google.
    This is indeed a very difficult puzzle, i wrote a python program and using the A* to solve it, and it takes a really long time.
    So, my question is how long does it take for your program to find the answer? Is there any special optimization? I rsearch the web but can’t find many useful information.

  4. Jason Wolfe said,

    April 4, 2011 @ 10:52 am

    There are only (9 !) / 2 = 181,440 reachable states in the 8-puzzle, so you should be able to solve any instance pretty quickly (on the order of seconds or less) even using brute force, with a decently fast implementation. Repeated-state checking (i.e., a closed list) and proper data structures are essential, of course.

  5. solnit said,

    August 16, 2011 @ 4:25 am

    These two states are the same state really. Let’s take first position.

     8 6 7
     2 5 4
     3 . 1
    

    You can reflect this position about main diagonal.

     8 2 3
     6 5 .
     7 4 1
    

    Then you can rename pieces. More precisely, you can swap pieces 2-4, 3-7 and 6-8. It is because in goal state these pieces are symmetric.

     6 4 7
     8 5 .
     3 2 1
    

    Note that this is second hardest position.
    Now try to do the same two steps for, say, the following position:

    Position A
     1 2 3
     . 5 6
     4 7 8
    

    After reflection:

     1 . 4
     2 5 7
     3 6 8
    

    After renaming pieces 2-4, 3-7 and 6-8:

    Position B
     1 . 2
     4 5 3
     7 8 6
    

    Position A can be solved in three moves: U L L (U means “move piece up”).
    Position B also can be solved in three moves: L U U.
    Moreover, solution to the position B can be obtained by replacing moves U,L,D,R with moves L,U,R,D respectively.
    The following position is self-symmetric:

     . 8 7
     6 5 4
     3 2 1
    

    If you reflect this position and then rename tiles you will return to the same position.

  6. Era Ahmadian said,

    November 22, 2011 @ 11:08 pm

    Hi Solnit
    we are working on an Optimezd Program which is solved 8 puzzle problem with A* algorithm and with OOP methods in C# .
    Our Program Can solve the 31-depth instance easily!
    but i have a question of you?!
    why u said The hardest eight-puzzle instances take 31 moves to solve?how can u prove it?!
    we have of instances that they needs more moves for solving!!!
    and the second question is the reflection instances are the same state with every goals position or just the standard one?
    truly yours,Era

RSS feed for comments on this post · TrackBack URI

Leave a Comment