Does a 15-puzzle always have a solution












8












$begingroup$


puzzle



For those that are not familiar with (this type of) sliding puzzles, basically you have a number of tiles on a board equal to (n * m) - 1 (possibly more holes if you want). The goal is to re-arrange the tiles in such a way that solves the puzzle.



The puzzle could be anything, from number games to images.



While writing a small app for this, I found that if I were to initialize the puzzle by randomly shuffle all of the pieces, I could end up in a situation where there is no solution if my puzzle was 2x2.



So the problem I have is: given a sliding puzzle with n-by-m dimensions, is there always a solution if there are a sufficient number of tiles (eg: a 3x3 board)? How would I even begin to prove this, or simply convince myself that it is the case?



If it is possible that a random shuffle could result in no-solution, then I'd have to figure out how to verify that there exists a solution, which is a completely different beast.










share|cite|improve this question











$endgroup$



migrated from programmers.stackexchange.com Apr 15 '14 at 14:12


This question came from our site for professionals, academics, and students working within the systems development life cycle.


















  • $begingroup$
    If it started in a solved position, simply doing the reverse of all the random moves would bring you back to it.
    $endgroup$
    – VBCPP
    Apr 14 '14 at 16:53






  • 7




    $begingroup$
    Wikipedia -> 15 puzzle -> Solvability: "Johnson & Story (1879) used a parity argument to show that half of the starting positions for the n-puzzle are impossible to resolve, no matter how many moves are made..."
    $endgroup$
    – gnat
    Apr 14 '14 at 16:56










  • $begingroup$
    Thanks, I didn't know there was a specific name for this class of puzzles.
    $endgroup$
    – That Umbrella Guy
    Apr 14 '14 at 17:36










  • $begingroup$
    If I'm understanding the conclusions correctly, if I just randomly swap two tiles at a time, for an even number of times, I should have a solvable configuration.
    $endgroup$
    – That Umbrella Guy
    Apr 14 '14 at 18:07






  • 1




    $begingroup$
    This question appears to be off-topic because it is about puzzles not programming. While algorithms are used to find (optimal) solutions to puzzles, this question is asking if a solution always exists.
    $endgroup$
    – GlenH7
    Apr 14 '14 at 22:40
















8












$begingroup$


puzzle



For those that are not familiar with (this type of) sliding puzzles, basically you have a number of tiles on a board equal to (n * m) - 1 (possibly more holes if you want). The goal is to re-arrange the tiles in such a way that solves the puzzle.



The puzzle could be anything, from number games to images.



While writing a small app for this, I found that if I were to initialize the puzzle by randomly shuffle all of the pieces, I could end up in a situation where there is no solution if my puzzle was 2x2.



So the problem I have is: given a sliding puzzle with n-by-m dimensions, is there always a solution if there are a sufficient number of tiles (eg: a 3x3 board)? How would I even begin to prove this, or simply convince myself that it is the case?



If it is possible that a random shuffle could result in no-solution, then I'd have to figure out how to verify that there exists a solution, which is a completely different beast.










share|cite|improve this question











$endgroup$



migrated from programmers.stackexchange.com Apr 15 '14 at 14:12


This question came from our site for professionals, academics, and students working within the systems development life cycle.


















  • $begingroup$
    If it started in a solved position, simply doing the reverse of all the random moves would bring you back to it.
    $endgroup$
    – VBCPP
    Apr 14 '14 at 16:53






  • 7




    $begingroup$
    Wikipedia -> 15 puzzle -> Solvability: "Johnson & Story (1879) used a parity argument to show that half of the starting positions for the n-puzzle are impossible to resolve, no matter how many moves are made..."
    $endgroup$
    – gnat
    Apr 14 '14 at 16:56










  • $begingroup$
    Thanks, I didn't know there was a specific name for this class of puzzles.
    $endgroup$
    – That Umbrella Guy
    Apr 14 '14 at 17:36










  • $begingroup$
    If I'm understanding the conclusions correctly, if I just randomly swap two tiles at a time, for an even number of times, I should have a solvable configuration.
    $endgroup$
    – That Umbrella Guy
    Apr 14 '14 at 18:07






  • 1




    $begingroup$
    This question appears to be off-topic because it is about puzzles not programming. While algorithms are used to find (optimal) solutions to puzzles, this question is asking if a solution always exists.
    $endgroup$
    – GlenH7
    Apr 14 '14 at 22:40














8












8








8


1



$begingroup$


puzzle



For those that are not familiar with (this type of) sliding puzzles, basically you have a number of tiles on a board equal to (n * m) - 1 (possibly more holes if you want). The goal is to re-arrange the tiles in such a way that solves the puzzle.



The puzzle could be anything, from number games to images.



While writing a small app for this, I found that if I were to initialize the puzzle by randomly shuffle all of the pieces, I could end up in a situation where there is no solution if my puzzle was 2x2.



So the problem I have is: given a sliding puzzle with n-by-m dimensions, is there always a solution if there are a sufficient number of tiles (eg: a 3x3 board)? How would I even begin to prove this, or simply convince myself that it is the case?



If it is possible that a random shuffle could result in no-solution, then I'd have to figure out how to verify that there exists a solution, which is a completely different beast.










share|cite|improve this question











$endgroup$




puzzle



For those that are not familiar with (this type of) sliding puzzles, basically you have a number of tiles on a board equal to (n * m) - 1 (possibly more holes if you want). The goal is to re-arrange the tiles in such a way that solves the puzzle.



The puzzle could be anything, from number games to images.



While writing a small app for this, I found that if I were to initialize the puzzle by randomly shuffle all of the pieces, I could end up in a situation where there is no solution if my puzzle was 2x2.



So the problem I have is: given a sliding puzzle with n-by-m dimensions, is there always a solution if there are a sufficient number of tiles (eg: a 3x3 board)? How would I even begin to prove this, or simply convince myself that it is the case?



If it is possible that a random shuffle could result in no-solution, then I'd have to figure out how to verify that there exists a solution, which is a completely different beast.







algorithms






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 24 '18 at 8:35









Glorfindel

3,41381930




3,41381930










asked Apr 14 '14 at 16:48









That Umbrella GuyThat Umbrella Guy

14614




14614




migrated from programmers.stackexchange.com Apr 15 '14 at 14:12


This question came from our site for professionals, academics, and students working within the systems development life cycle.









migrated from programmers.stackexchange.com Apr 15 '14 at 14:12


This question came from our site for professionals, academics, and students working within the systems development life cycle.














  • $begingroup$
    If it started in a solved position, simply doing the reverse of all the random moves would bring you back to it.
    $endgroup$
    – VBCPP
    Apr 14 '14 at 16:53






  • 7




    $begingroup$
    Wikipedia -> 15 puzzle -> Solvability: "Johnson & Story (1879) used a parity argument to show that half of the starting positions for the n-puzzle are impossible to resolve, no matter how many moves are made..."
    $endgroup$
    – gnat
    Apr 14 '14 at 16:56










  • $begingroup$
    Thanks, I didn't know there was a specific name for this class of puzzles.
    $endgroup$
    – That Umbrella Guy
    Apr 14 '14 at 17:36










  • $begingroup$
    If I'm understanding the conclusions correctly, if I just randomly swap two tiles at a time, for an even number of times, I should have a solvable configuration.
    $endgroup$
    – That Umbrella Guy
    Apr 14 '14 at 18:07






  • 1




    $begingroup$
    This question appears to be off-topic because it is about puzzles not programming. While algorithms are used to find (optimal) solutions to puzzles, this question is asking if a solution always exists.
    $endgroup$
    – GlenH7
    Apr 14 '14 at 22:40


















  • $begingroup$
    If it started in a solved position, simply doing the reverse of all the random moves would bring you back to it.
    $endgroup$
    – VBCPP
    Apr 14 '14 at 16:53






  • 7




    $begingroup$
    Wikipedia -> 15 puzzle -> Solvability: "Johnson & Story (1879) used a parity argument to show that half of the starting positions for the n-puzzle are impossible to resolve, no matter how many moves are made..."
    $endgroup$
    – gnat
    Apr 14 '14 at 16:56










  • $begingroup$
    Thanks, I didn't know there was a specific name for this class of puzzles.
    $endgroup$
    – That Umbrella Guy
    Apr 14 '14 at 17:36










  • $begingroup$
    If I'm understanding the conclusions correctly, if I just randomly swap two tiles at a time, for an even number of times, I should have a solvable configuration.
    $endgroup$
    – That Umbrella Guy
    Apr 14 '14 at 18:07






  • 1




    $begingroup$
    This question appears to be off-topic because it is about puzzles not programming. While algorithms are used to find (optimal) solutions to puzzles, this question is asking if a solution always exists.
    $endgroup$
    – GlenH7
    Apr 14 '14 at 22:40
















$begingroup$
If it started in a solved position, simply doing the reverse of all the random moves would bring you back to it.
$endgroup$
– VBCPP
Apr 14 '14 at 16:53




$begingroup$
If it started in a solved position, simply doing the reverse of all the random moves would bring you back to it.
$endgroup$
– VBCPP
Apr 14 '14 at 16:53




7




7




$begingroup$
Wikipedia -> 15 puzzle -> Solvability: "Johnson & Story (1879) used a parity argument to show that half of the starting positions for the n-puzzle are impossible to resolve, no matter how many moves are made..."
$endgroup$
– gnat
Apr 14 '14 at 16:56




$begingroup$
Wikipedia -> 15 puzzle -> Solvability: "Johnson & Story (1879) used a parity argument to show that half of the starting positions for the n-puzzle are impossible to resolve, no matter how many moves are made..."
$endgroup$
– gnat
Apr 14 '14 at 16:56












$begingroup$
Thanks, I didn't know there was a specific name for this class of puzzles.
$endgroup$
– That Umbrella Guy
Apr 14 '14 at 17:36




$begingroup$
Thanks, I didn't know there was a specific name for this class of puzzles.
$endgroup$
– That Umbrella Guy
Apr 14 '14 at 17:36












$begingroup$
If I'm understanding the conclusions correctly, if I just randomly swap two tiles at a time, for an even number of times, I should have a solvable configuration.
$endgroup$
– That Umbrella Guy
Apr 14 '14 at 18:07




$begingroup$
If I'm understanding the conclusions correctly, if I just randomly swap two tiles at a time, for an even number of times, I should have a solvable configuration.
$endgroup$
– That Umbrella Guy
Apr 14 '14 at 18:07




1




1




$begingroup$
This question appears to be off-topic because it is about puzzles not programming. While algorithms are used to find (optimal) solutions to puzzles, this question is asking if a solution always exists.
$endgroup$
– GlenH7
Apr 14 '14 at 22:40




$begingroup$
This question appears to be off-topic because it is about puzzles not programming. While algorithms are used to find (optimal) solutions to puzzles, this question is asking if a solution always exists.
$endgroup$
– GlenH7
Apr 14 '14 at 22:40










5 Answers
5






active

oldest

votes


















6












$begingroup$

Martin Gardner had a very good writeup on the 14-15 puzzle in one of his Mathematical Games books.



Sam Loyd invented the puzzle. He periodically posted rewards for solutions to certain starting configurations. None of those rewards were claimed.



Much analysis was expended, and it was finally determined, through a parity argument (as mentioned in the comment above), that half of the possible starting configurations were unsolvable. Interestingly, ALL of Loyd's reward configurations were unsolvable.



SO: No, every possible configuration is not solvable. If you START with a solved puzzle, and apply only legal transformations (moves) to it, you always wind up at a solvable configuration.



For the GENERAL nxm question, you'd probably have to expand the parity argument.






share|cite|improve this answer









$endgroup$









  • 1




    $begingroup$
    You don't have to expand the parity argument at all. The puzzle is solvable precisely when the parity of the configuration is even. This applies to general $n times m$ as well, as long as $n,m ge 3$ so you have enough room.
    $endgroup$
    – Ross Millikan
    Apr 15 '14 at 14:24



















3












$begingroup$

Just a hint. Once I had to show with basic algebra (permutation groups) that a standard $15$ puzzle had no solution. The idea there was the following:



to rearrange the puzzle, you have to perform a permutation of the $15$ tiles.



Now, notice that once you write any permutation allowed, it is written as a product of an even number of $2$-cycles (you always move the "empty" tile, it starts in the corner and it has to be still there at the end of your moves). Hence permutation with sign $-1$ are not allowed.



In my case it was enough to conclude the puzzle had no solution (I had to perform an exchange between two tiles, so it had sign $-1$). Maybe it can help you to exclude some configurations.






share|cite|improve this answer









$endgroup$





















    1












    $begingroup$

    Yes, it will always have a solution as long as you start with a good solution and then make legal moves to randomize the tiles.



    BUT if you, for example, pop two pieces out and switch them, then you can get an insolvable puzzle. ;) As you discovered.






    share|cite|improve this answer









    $endgroup$





















      1












      $begingroup$

      The solvability of an n puzzle can be tested after shuffling by computing the permutations of the puzzle. "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable."



      For the math behind this, please see http://mathworld.wolfram.com/15Puzzle.html






      share|cite|improve this answer











      $endgroup$













      • $begingroup$
        While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
        $endgroup$
        – Joey Zou
        Oct 3 '16 at 3:14






      • 1




        $begingroup$
        The answer is useful and is summarized in "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable." The provided link is a reliable one.
        $endgroup$
        – Kokeb
        Oct 3 '16 at 15:00





















      -1












      $begingroup$

      Here, we consider the following problem:
      For a given position on the board to say whether there is a sequence of moves leading to a decision or not.



      Let there be given a position on the board:



      +------------------+.  
      | 11 | 15 | 2 | 13 |.
      |----|----|---|----|.
      | 14 | 1 | 8 | 3 |.
      |----|----|---|----|.
      | 7 | 6 | 0 | 10 |.
      |----|----|---|----|.
      | 4 | 12 | 9 | 5 |.
      +------------------+.


      wherein one of the elements is zero and indicates an empty cell.
      Consider the numbers in the matrix serially (rowwise):



      11 12 2 13 14 1 8 3 7 6 0 10 4 12 9 5


      Denote N - the number of inversions in the permutation (i.e. the number of such elements a[i] and a[j] that i < j but a[i] > a[j]).



      Next, let K- line number in which there is an empty element (i.e. in our notation K = 3).



      Then, a solution exists if and only if N + K is even.






      share|cite|improve this answer











      $endgroup$









      • 1




        $begingroup$
        I tried to edit your post to make the math formatting work, but I failed (partly because I could not understand some of it). Have a look at the introduction to posting mathematical expressions.
        $endgroup$
        – hardmath
        May 31 '17 at 2:08










      • $begingroup$
        Thanks @hardmath. Fixed the formatting.
        $endgroup$
        – Deepak gupta
        Aug 2 '17 at 12:23












      Your Answer





      StackExchange.ifUsing("editor", function () {
      return StackExchange.using("mathjaxEditing", function () {
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      });
      });
      }, "mathjax-editing");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "69"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      noCode: true, onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f754827%2fdoes-a-15-puzzle-always-have-a-solution%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      6












      $begingroup$

      Martin Gardner had a very good writeup on the 14-15 puzzle in one of his Mathematical Games books.



      Sam Loyd invented the puzzle. He periodically posted rewards for solutions to certain starting configurations. None of those rewards were claimed.



      Much analysis was expended, and it was finally determined, through a parity argument (as mentioned in the comment above), that half of the possible starting configurations were unsolvable. Interestingly, ALL of Loyd's reward configurations were unsolvable.



      SO: No, every possible configuration is not solvable. If you START with a solved puzzle, and apply only legal transformations (moves) to it, you always wind up at a solvable configuration.



      For the GENERAL nxm question, you'd probably have to expand the parity argument.






      share|cite|improve this answer









      $endgroup$









      • 1




        $begingroup$
        You don't have to expand the parity argument at all. The puzzle is solvable precisely when the parity of the configuration is even. This applies to general $n times m$ as well, as long as $n,m ge 3$ so you have enough room.
        $endgroup$
        – Ross Millikan
        Apr 15 '14 at 14:24
















      6












      $begingroup$

      Martin Gardner had a very good writeup on the 14-15 puzzle in one of his Mathematical Games books.



      Sam Loyd invented the puzzle. He periodically posted rewards for solutions to certain starting configurations. None of those rewards were claimed.



      Much analysis was expended, and it was finally determined, through a parity argument (as mentioned in the comment above), that half of the possible starting configurations were unsolvable. Interestingly, ALL of Loyd's reward configurations were unsolvable.



      SO: No, every possible configuration is not solvable. If you START with a solved puzzle, and apply only legal transformations (moves) to it, you always wind up at a solvable configuration.



      For the GENERAL nxm question, you'd probably have to expand the parity argument.






      share|cite|improve this answer









      $endgroup$









      • 1




        $begingroup$
        You don't have to expand the parity argument at all. The puzzle is solvable precisely when the parity of the configuration is even. This applies to general $n times m$ as well, as long as $n,m ge 3$ so you have enough room.
        $endgroup$
        – Ross Millikan
        Apr 15 '14 at 14:24














      6












      6








      6





      $begingroup$

      Martin Gardner had a very good writeup on the 14-15 puzzle in one of his Mathematical Games books.



      Sam Loyd invented the puzzle. He periodically posted rewards for solutions to certain starting configurations. None of those rewards were claimed.



      Much analysis was expended, and it was finally determined, through a parity argument (as mentioned in the comment above), that half of the possible starting configurations were unsolvable. Interestingly, ALL of Loyd's reward configurations were unsolvable.



      SO: No, every possible configuration is not solvable. If you START with a solved puzzle, and apply only legal transformations (moves) to it, you always wind up at a solvable configuration.



      For the GENERAL nxm question, you'd probably have to expand the parity argument.






      share|cite|improve this answer









      $endgroup$



      Martin Gardner had a very good writeup on the 14-15 puzzle in one of his Mathematical Games books.



      Sam Loyd invented the puzzle. He periodically posted rewards for solutions to certain starting configurations. None of those rewards were claimed.



      Much analysis was expended, and it was finally determined, through a parity argument (as mentioned in the comment above), that half of the possible starting configurations were unsolvable. Interestingly, ALL of Loyd's reward configurations were unsolvable.



      SO: No, every possible configuration is not solvable. If you START with a solved puzzle, and apply only legal transformations (moves) to it, you always wind up at a solvable configuration.



      For the GENERAL nxm question, you'd probably have to expand the parity argument.







      share|cite|improve this answer












      share|cite|improve this answer



      share|cite|improve this answer










      answered Apr 14 '14 at 17:31









      John R. StrohmJohn R. Strohm

      1763




      1763








      • 1




        $begingroup$
        You don't have to expand the parity argument at all. The puzzle is solvable precisely when the parity of the configuration is even. This applies to general $n times m$ as well, as long as $n,m ge 3$ so you have enough room.
        $endgroup$
        – Ross Millikan
        Apr 15 '14 at 14:24














      • 1




        $begingroup$
        You don't have to expand the parity argument at all. The puzzle is solvable precisely when the parity of the configuration is even. This applies to general $n times m$ as well, as long as $n,m ge 3$ so you have enough room.
        $endgroup$
        – Ross Millikan
        Apr 15 '14 at 14:24








      1




      1




      $begingroup$
      You don't have to expand the parity argument at all. The puzzle is solvable precisely when the parity of the configuration is even. This applies to general $n times m$ as well, as long as $n,m ge 3$ so you have enough room.
      $endgroup$
      – Ross Millikan
      Apr 15 '14 at 14:24




      $begingroup$
      You don't have to expand the parity argument at all. The puzzle is solvable precisely when the parity of the configuration is even. This applies to general $n times m$ as well, as long as $n,m ge 3$ so you have enough room.
      $endgroup$
      – Ross Millikan
      Apr 15 '14 at 14:24











      3












      $begingroup$

      Just a hint. Once I had to show with basic algebra (permutation groups) that a standard $15$ puzzle had no solution. The idea there was the following:



      to rearrange the puzzle, you have to perform a permutation of the $15$ tiles.



      Now, notice that once you write any permutation allowed, it is written as a product of an even number of $2$-cycles (you always move the "empty" tile, it starts in the corner and it has to be still there at the end of your moves). Hence permutation with sign $-1$ are not allowed.



      In my case it was enough to conclude the puzzle had no solution (I had to perform an exchange between two tiles, so it had sign $-1$). Maybe it can help you to exclude some configurations.






      share|cite|improve this answer









      $endgroup$


















        3












        $begingroup$

        Just a hint. Once I had to show with basic algebra (permutation groups) that a standard $15$ puzzle had no solution. The idea there was the following:



        to rearrange the puzzle, you have to perform a permutation of the $15$ tiles.



        Now, notice that once you write any permutation allowed, it is written as a product of an even number of $2$-cycles (you always move the "empty" tile, it starts in the corner and it has to be still there at the end of your moves). Hence permutation with sign $-1$ are not allowed.



        In my case it was enough to conclude the puzzle had no solution (I had to perform an exchange between two tiles, so it had sign $-1$). Maybe it can help you to exclude some configurations.






        share|cite|improve this answer









        $endgroup$
















          3












          3








          3





          $begingroup$

          Just a hint. Once I had to show with basic algebra (permutation groups) that a standard $15$ puzzle had no solution. The idea there was the following:



          to rearrange the puzzle, you have to perform a permutation of the $15$ tiles.



          Now, notice that once you write any permutation allowed, it is written as a product of an even number of $2$-cycles (you always move the "empty" tile, it starts in the corner and it has to be still there at the end of your moves). Hence permutation with sign $-1$ are not allowed.



          In my case it was enough to conclude the puzzle had no solution (I had to perform an exchange between two tiles, so it had sign $-1$). Maybe it can help you to exclude some configurations.






          share|cite|improve this answer









          $endgroup$



          Just a hint. Once I had to show with basic algebra (permutation groups) that a standard $15$ puzzle had no solution. The idea there was the following:



          to rearrange the puzzle, you have to perform a permutation of the $15$ tiles.



          Now, notice that once you write any permutation allowed, it is written as a product of an even number of $2$-cycles (you always move the "empty" tile, it starts in the corner and it has to be still there at the end of your moves). Hence permutation with sign $-1$ are not allowed.



          In my case it was enough to conclude the puzzle had no solution (I had to perform an exchange between two tiles, so it had sign $-1$). Maybe it can help you to exclude some configurations.







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered Apr 15 '14 at 14:24









          StefanoStefano

          2,223931




          2,223931























              1












              $begingroup$

              Yes, it will always have a solution as long as you start with a good solution and then make legal moves to randomize the tiles.



              BUT if you, for example, pop two pieces out and switch them, then you can get an insolvable puzzle. ;) As you discovered.






              share|cite|improve this answer









              $endgroup$


















                1












                $begingroup$

                Yes, it will always have a solution as long as you start with a good solution and then make legal moves to randomize the tiles.



                BUT if you, for example, pop two pieces out and switch them, then you can get an insolvable puzzle. ;) As you discovered.






                share|cite|improve this answer









                $endgroup$
















                  1












                  1








                  1





                  $begingroup$

                  Yes, it will always have a solution as long as you start with a good solution and then make legal moves to randomize the tiles.



                  BUT if you, for example, pop two pieces out and switch them, then you can get an insolvable puzzle. ;) As you discovered.






                  share|cite|improve this answer









                  $endgroup$



                  Yes, it will always have a solution as long as you start with a good solution and then make legal moves to randomize the tiles.



                  BUT if you, for example, pop two pieces out and switch them, then you can get an insolvable puzzle. ;) As you discovered.







                  share|cite|improve this answer












                  share|cite|improve this answer



                  share|cite|improve this answer










                  answered Apr 14 '14 at 16:56









                  RobRob

                  23119




                  23119























                      1












                      $begingroup$

                      The solvability of an n puzzle can be tested after shuffling by computing the permutations of the puzzle. "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable."



                      For the math behind this, please see http://mathworld.wolfram.com/15Puzzle.html






                      share|cite|improve this answer











                      $endgroup$













                      • $begingroup$
                        While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                        $endgroup$
                        – Joey Zou
                        Oct 3 '16 at 3:14






                      • 1




                        $begingroup$
                        The answer is useful and is summarized in "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable." The provided link is a reliable one.
                        $endgroup$
                        – Kokeb
                        Oct 3 '16 at 15:00


















                      1












                      $begingroup$

                      The solvability of an n puzzle can be tested after shuffling by computing the permutations of the puzzle. "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable."



                      For the math behind this, please see http://mathworld.wolfram.com/15Puzzle.html






                      share|cite|improve this answer











                      $endgroup$













                      • $begingroup$
                        While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                        $endgroup$
                        – Joey Zou
                        Oct 3 '16 at 3:14






                      • 1




                        $begingroup$
                        The answer is useful and is summarized in "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable." The provided link is a reliable one.
                        $endgroup$
                        – Kokeb
                        Oct 3 '16 at 15:00
















                      1












                      1








                      1





                      $begingroup$

                      The solvability of an n puzzle can be tested after shuffling by computing the permutations of the puzzle. "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable."



                      For the math behind this, please see http://mathworld.wolfram.com/15Puzzle.html






                      share|cite|improve this answer











                      $endgroup$



                      The solvability of an n puzzle can be tested after shuffling by computing the permutations of the puzzle. "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable."



                      For the math behind this, please see http://mathworld.wolfram.com/15Puzzle.html







                      share|cite|improve this answer














                      share|cite|improve this answer



                      share|cite|improve this answer








                      edited Oct 3 '16 at 14:45

























                      answered Oct 3 '16 at 2:47









                      KokebKokeb

                      112




                      112












                      • $begingroup$
                        While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                        $endgroup$
                        – Joey Zou
                        Oct 3 '16 at 3:14






                      • 1




                        $begingroup$
                        The answer is useful and is summarized in "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable." The provided link is a reliable one.
                        $endgroup$
                        – Kokeb
                        Oct 3 '16 at 15:00




















                      • $begingroup$
                        While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                        $endgroup$
                        – Joey Zou
                        Oct 3 '16 at 3:14






                      • 1




                        $begingroup$
                        The answer is useful and is summarized in "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable." The provided link is a reliable one.
                        $endgroup$
                        – Kokeb
                        Oct 3 '16 at 15:00


















                      $begingroup$
                      While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                      $endgroup$
                      – Joey Zou
                      Oct 3 '16 at 3:14




                      $begingroup$
                      While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                      $endgroup$
                      – Joey Zou
                      Oct 3 '16 at 3:14




                      1




                      1




                      $begingroup$
                      The answer is useful and is summarized in "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable." The provided link is a reliable one.
                      $endgroup$
                      – Kokeb
                      Oct 3 '16 at 15:00






                      $begingroup$
                      The answer is useful and is summarized in "While odd permutations of the puzzle are impossible to solve, all even permutations are solvable." The provided link is a reliable one.
                      $endgroup$
                      – Kokeb
                      Oct 3 '16 at 15:00













                      -1












                      $begingroup$

                      Here, we consider the following problem:
                      For a given position on the board to say whether there is a sequence of moves leading to a decision or not.



                      Let there be given a position on the board:



                      +------------------+.  
                      | 11 | 15 | 2 | 13 |.
                      |----|----|---|----|.
                      | 14 | 1 | 8 | 3 |.
                      |----|----|---|----|.
                      | 7 | 6 | 0 | 10 |.
                      |----|----|---|----|.
                      | 4 | 12 | 9 | 5 |.
                      +------------------+.


                      wherein one of the elements is zero and indicates an empty cell.
                      Consider the numbers in the matrix serially (rowwise):



                      11 12 2 13 14 1 8 3 7 6 0 10 4 12 9 5


                      Denote N - the number of inversions in the permutation (i.e. the number of such elements a[i] and a[j] that i < j but a[i] > a[j]).



                      Next, let K- line number in which there is an empty element (i.e. in our notation K = 3).



                      Then, a solution exists if and only if N + K is even.






                      share|cite|improve this answer











                      $endgroup$









                      • 1




                        $begingroup$
                        I tried to edit your post to make the math formatting work, but I failed (partly because I could not understand some of it). Have a look at the introduction to posting mathematical expressions.
                        $endgroup$
                        – hardmath
                        May 31 '17 at 2:08










                      • $begingroup$
                        Thanks @hardmath. Fixed the formatting.
                        $endgroup$
                        – Deepak gupta
                        Aug 2 '17 at 12:23
















                      -1












                      $begingroup$

                      Here, we consider the following problem:
                      For a given position on the board to say whether there is a sequence of moves leading to a decision or not.



                      Let there be given a position on the board:



                      +------------------+.  
                      | 11 | 15 | 2 | 13 |.
                      |----|----|---|----|.
                      | 14 | 1 | 8 | 3 |.
                      |----|----|---|----|.
                      | 7 | 6 | 0 | 10 |.
                      |----|----|---|----|.
                      | 4 | 12 | 9 | 5 |.
                      +------------------+.


                      wherein one of the elements is zero and indicates an empty cell.
                      Consider the numbers in the matrix serially (rowwise):



                      11 12 2 13 14 1 8 3 7 6 0 10 4 12 9 5


                      Denote N - the number of inversions in the permutation (i.e. the number of such elements a[i] and a[j] that i < j but a[i] > a[j]).



                      Next, let K- line number in which there is an empty element (i.e. in our notation K = 3).



                      Then, a solution exists if and only if N + K is even.






                      share|cite|improve this answer











                      $endgroup$









                      • 1




                        $begingroup$
                        I tried to edit your post to make the math formatting work, but I failed (partly because I could not understand some of it). Have a look at the introduction to posting mathematical expressions.
                        $endgroup$
                        – hardmath
                        May 31 '17 at 2:08










                      • $begingroup$
                        Thanks @hardmath. Fixed the formatting.
                        $endgroup$
                        – Deepak gupta
                        Aug 2 '17 at 12:23














                      -1












                      -1








                      -1





                      $begingroup$

                      Here, we consider the following problem:
                      For a given position on the board to say whether there is a sequence of moves leading to a decision or not.



                      Let there be given a position on the board:



                      +------------------+.  
                      | 11 | 15 | 2 | 13 |.
                      |----|----|---|----|.
                      | 14 | 1 | 8 | 3 |.
                      |----|----|---|----|.
                      | 7 | 6 | 0 | 10 |.
                      |----|----|---|----|.
                      | 4 | 12 | 9 | 5 |.
                      +------------------+.


                      wherein one of the elements is zero and indicates an empty cell.
                      Consider the numbers in the matrix serially (rowwise):



                      11 12 2 13 14 1 8 3 7 6 0 10 4 12 9 5


                      Denote N - the number of inversions in the permutation (i.e. the number of such elements a[i] and a[j] that i < j but a[i] > a[j]).



                      Next, let K- line number in which there is an empty element (i.e. in our notation K = 3).



                      Then, a solution exists if and only if N + K is even.






                      share|cite|improve this answer











                      $endgroup$



                      Here, we consider the following problem:
                      For a given position on the board to say whether there is a sequence of moves leading to a decision or not.



                      Let there be given a position on the board:



                      +------------------+.  
                      | 11 | 15 | 2 | 13 |.
                      |----|----|---|----|.
                      | 14 | 1 | 8 | 3 |.
                      |----|----|---|----|.
                      | 7 | 6 | 0 | 10 |.
                      |----|----|---|----|.
                      | 4 | 12 | 9 | 5 |.
                      +------------------+.


                      wherein one of the elements is zero and indicates an empty cell.
                      Consider the numbers in the matrix serially (rowwise):



                      11 12 2 13 14 1 8 3 7 6 0 10 4 12 9 5


                      Denote N - the number of inversions in the permutation (i.e. the number of such elements a[i] and a[j] that i < j but a[i] > a[j]).



                      Next, let K- line number in which there is an empty element (i.e. in our notation K = 3).



                      Then, a solution exists if and only if N + K is even.







                      share|cite|improve this answer














                      share|cite|improve this answer



                      share|cite|improve this answer








                      edited Aug 2 '17 at 12:23

























                      answered May 31 '17 at 1:25









                      Deepak guptaDeepak gupta

                      364




                      364








                      • 1




                        $begingroup$
                        I tried to edit your post to make the math formatting work, but I failed (partly because I could not understand some of it). Have a look at the introduction to posting mathematical expressions.
                        $endgroup$
                        – hardmath
                        May 31 '17 at 2:08










                      • $begingroup$
                        Thanks @hardmath. Fixed the formatting.
                        $endgroup$
                        – Deepak gupta
                        Aug 2 '17 at 12:23














                      • 1




                        $begingroup$
                        I tried to edit your post to make the math formatting work, but I failed (partly because I could not understand some of it). Have a look at the introduction to posting mathematical expressions.
                        $endgroup$
                        – hardmath
                        May 31 '17 at 2:08










                      • $begingroup$
                        Thanks @hardmath. Fixed the formatting.
                        $endgroup$
                        – Deepak gupta
                        Aug 2 '17 at 12:23








                      1




                      1




                      $begingroup$
                      I tried to edit your post to make the math formatting work, but I failed (partly because I could not understand some of it). Have a look at the introduction to posting mathematical expressions.
                      $endgroup$
                      – hardmath
                      May 31 '17 at 2:08




                      $begingroup$
                      I tried to edit your post to make the math formatting work, but I failed (partly because I could not understand some of it). Have a look at the introduction to posting mathematical expressions.
                      $endgroup$
                      – hardmath
                      May 31 '17 at 2:08












                      $begingroup$
                      Thanks @hardmath. Fixed the formatting.
                      $endgroup$
                      – Deepak gupta
                      Aug 2 '17 at 12:23




                      $begingroup$
                      Thanks @hardmath. Fixed the formatting.
                      $endgroup$
                      – Deepak gupta
                      Aug 2 '17 at 12:23


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Mathematics Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f754827%2fdoes-a-15-puzzle-always-have-a-solution%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Willebadessen

                      Ida-Boy-Ed-Garten

                      Residenzschloss Arolsen