1. Home
  2. Explore
  3. Mathematics
  4. 15 Puzzle Math

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

15 Puzzle Math

Speaker 1Speaker 2

15 Puzzle Math

16:08
0:00-16:08
  1. Corey

    Okay, so today we're going to talk about this fantastic little puzzle. It's called the 15 puzzle. You can see it's a tray with 15 little squares, each numbered 1 through 15, and one blank.

  2. Maria

    Right, and we can move the squares around. Let's say we want to get these in order. So I'm going to move these around. I've got 1, 2, 3 already. Then the third row should have 9, 10, 11, 12, and then 13, 14, 15. Oh, you're good at that!

  3. Corey

    So there we go. We can only make moves where we switch one tile with the empty spot. I can't switch this one and that one, for example, because there's no blank to move them around in. What we want to talk about is the mathematics behind it.

  4. Maria

    We went out yesterday and found some examples of these puzzles in stores. We found something very interesting on the back of the package. It shows you some patterns you might try to arrange the tiles in.

  5. Corey

    The one we just did was 1 through 15. Here, this one has 1, 2, 3, 4 in vertical lines rather than horizontal. You might want to do evens and odds, or even reverse order from 15 down to 1.

  6. Maria

    But this is very curious: try as you might, you will never be able to do this arrangement. How they ended up on the back of this package is a real mystery, but that's what we want to explain today.

  7. Corey

    So, they're giving people an impossible task? It seems like it. I don't know what they were thinking. Did you play this game when you were a boy?

  8. Maria

    I had several versions, including the standard ones. I also had some with pictures instead of numbers. I had one with a map of the world. Yes, I certainly wasted more time than I should have on these puzzles.

  9. Corey

    It was invented around the 1870s. A famous American puzzle maker named Sam Loyd claimed he invented it, but apparently, that's not the case. What he did do, however, was issue a public challenge.

  10. Maria

    He offered $1,000 to anyone who could take the 15 puzzle, arranged 1 through 15, and rearrange it so that 14 and 15 were switched. The sneaky thing is, this is also an impossible arrangement!

  11. Corey

    This caused an absolute national frenzy. Everybody was trying to do it. A serious mathematics research journal, the American Journal of Mathematics, even published a paper called 'Notes on the 15 Puzzle'.

  12. Maria

    The editor said, "The 15 puzzle for the last few weeks has been prominently before the American public and may safely be said to have engaged the attention of nine out of ten persons of both sexes and of all ages and conditions of the community."

  13. Corey

    He went on to say that this wouldn't have been enough to persuade them to publish a paper, but they felt it was a chance to educate the public on some important mathematical concepts. So they were jumping on the bandwagon?

  14. Maria

    Actually, this paper contains two short notes: one proving some configurations are impossible, and the other detailing exactly which ones are possible. Okay, so first, we have to convert this puzzle into mathematical language.

  15. Corey

    Exactly. We need to use the tools of mathematics to figure out what's going on. Let's start by putting everything on the same footing. Let's think of the blank square as the number 16.

  16. Maria

    So now we've got the numbers 1 through 16 in some order. We're going to focus on those lists of numbers. Each arrangement of the tiles will be thought of as an arrangement of the numbers from 1 to 16.

  17. Corey

    Every time we have a pattern, I'm going to write down the list of numbers 1 through 16 in the order they appear in the tray. For example, this arrangement would give me the list 5, 1, 3 (remember, blank is 16), then 9, 2, 6, 4, 13, 10, 7, 8, 14, 15, 12, 11.

  18. Maria

    So it's the same set of numbers 1 through 16, just written in a different order. In mathematics, that's called a permutation. In our case, it's a permutation of the numbers from 1 all the way up to 16.

  19. Corey

    At this point, I would have assumed every permutation is possible. If you juggle them around enough times, you can list the numbers in any order, right?

  20. Maria

    That would be a reasonable assumption, and if that were possible, anything on the back of this package would be fair game. What we need to show is that among all permutations, some have one property that's good for us, and some have a different property that's bad.

  21. Corey

    We're going to use this property we'll identify as a way to distinguish the possible from the impossible. So, let's think about what a sliding move actually does to the permutation.

  22. Maria

    When we slide a piece, we're swapping the blank square from where it is to where the piece we slid into it came from. So 16 and 4 have switched places if I make that move. If I moved the blank into the 3's spot, 16 and 3 have switched.

  23. Corey

    So the moves we're allowed correspond to switching one number with just one other. In our case, we can always switch 16 with something else, let's just say X. I'll write it as (16, X).

  24. Maria

    When you write a pair like that, it means switch 16 with X. If I do that, I obviously get a new permutation. So we've now translated our puzzle into the mathematical problem of starting from one configuration and getting to another by doing switches like this.

  25. Corey

    These are called transpositions. Now that we've translated it into mathematics, we get to use everything mathematicians have learned about permutations and transpositions. There are a couple of crucial facts we need to use.

  26. Maria

    The first fact: we can convert the permutation we start with - everything in order - into any other permutation of the same numbers using only transpositions. So you're including the impossible ones at this point?

  27. Corey

    At this point, those impossible configurations are within our reach. True, if we're free from the constraints of the puzzle and only dealing with the permutations, then we can convert any one into any other.

  28. Maria

    Alright, simple example with permutations of just 1, 2, 3. Let's suppose we want to end up with 3, 1, 2. How can we convert 1, 2, 3 into 3, 1, 2?

  29. Corey

    We can first get 3 into the place we want it to go by switching 3 and 1. So we make the transposition (1,3). That will turn this into 3, 2, 1. We haven't done anything to 2, but we've switched 1 and 3.

  30. Maria

    And now I get the 1 into place. So now I switch the 1 and the 2, and there we are, from there to there by two permutations. If you have a longer set of numbers, you might need more, but that's the idea.

  31. Corey

    You can get from any one permutation to any other just by switching two at a time. Fact 2 addresses there being more than one way to get from one to another. We can always do it by transpositions, but for example, in the case of these two permutations, I could have done something different.

  32. Maria

    Okay, now let me show you a longer one, again going from 1, 2, 3 to 3, 1, 2. First, switch the 1. Now, let me move 3 over by switching it first with 1, and then with 2.

  33. Corey

    And now I still have to get 1 and 2 into the right place. So that will take one more switch, switching 1 and 2, which will put this into the right place. So now I've got a chain going from 1, 2, 3 to 3, 1, 2 that involves one, two, three, four steps.

  34. Maria

    Whereas in our original example, we only had two steps. Can you show me a three-step example?

  35. Corey

    I cannot, because of Fact 2. And Fact 2 says that even though there are many ways to get from one permutation to another, they don't have to involve the same number of steps, but if one path involves an even number of steps, then all paths have to have an even number of steps.

  36. Maria

    So the number is not fixed, but the parity - whether it's even or odd - is fixed. So it could have been odd? Like, with some numbers, it will be odd as well?

  37. Corey

    Right, between some permutations. For example, if we wanted to go from 1, 2, 3 to 3, 2, 1, then I would have only needed one step, or three steps, or five steps. So Fact number two: the number of steps required is not fixed.

  38. Maria

    But the parity of that number - whether it's even or odd - is fixed. I'm taking your word for that. That's like a proven thing, right?

  39. Corey

    Right, we're taking these as facts that- And not just because we want them to be - these are proven facts. Right, right. These are, you might even call them, theorems about permutations.

  40. Maria

    So like in the example we did, we had one path that had two steps and one that had four. The number was different, but both were even. And I could try until the end of the universe to do three and I wouldn't find it.

  41. Corey

    You wouldn't find it. Yeah. Or 5, or 7, or 9, even if I was like duplicating my steps and things.

  42. Maria

    Right, you could have a sequence where you just went 'round and 'round in a loop for a while and then cut out of the loop and made progress. That would add a lot of unnecessary steps, but it wouldn't change the parity of the number of steps.

  43. Corey

    So what this means is that, starting from the numbers in order, every other permutation is reached either by an even number of steps or an odd number of steps. Another way of saying that is we can attach to each permutation a thing we might call an invariant of the permutation, which is the parity of the number of steps needed to get to it from the starting configuration.

  44. Maria

    Now that we know that all permutations are either even or odd, we will see that the impossible ones have the wrong parity. When we go back to our puzzle and want to know which configurations are possible and which are impossible, we're going to use this relation to even and odd permutations.

  45. Corey

    We'll see that if the arrangement corresponds to a permutation with the wrong parity, then we'll never be able to get to it. One extra consideration we have to bring in is we have to look at where the blank space, the number 16 in our permutations, starts and ends.

  46. Maria

    So, for example, if we wanted to start with the pieces all in a horizontal row, let's suppose we wanted to get to the vertical arrangement. Here we see that in this vertical arrangement, we're going to end up with the blank square again at the bottom there.

  47. Corey

    So if we start and end with the number 16 - or in puzzle language, the blank square - starting in the bottom-right corner and ending in the same place, what's going to happen is that the blank square is going to move all around the tray as we make our switching.

  48. Maria

    So here I'll start it. We want to get to the ending configuration. So we have to move the blank square all around so that I can rearrange the numbers. Keep your eye on the blank square. You can see it's moving all over the board, and we will just keep moving the blank square around until the pieces do what we want, etc.

  49. Corey

    So let's count how many times we have to move the blank. That will be the number of transpositions we have to do. You might think this is an impossible thing, I mean there's going to be maybe dozens, maybe hundreds of moves that we have to make, but remember, all that we care about is the parity of the number of moves.

  50. Maria

    And if we think about what's going to happen to this blank square if it's going to start here and end up at the same place. Let's suppose that when we're doing this, we make a certain number of moves to the left, a certain number of moves to the right, a certain number of moves up, and a certain number of moves down.

  51. Corey

    If we're going to end up at the same place, we have to make as many left as right, because every time we move left, we'll have to compensate if we're going to end up back at the same place, and the same with up and down. The number of ups will have to equal the number of downs.

  52. Maria

    So the total number of moves is the total of the lefts and the rights and the ups and the downs. But the lefts and the rights are the same, so I can write that as twice the number of lefts, and there are as many downs as ups, so that's twice the number of ups.

  53. Corey

    So you can see that whatever the number is, it's twice something. It's even. It's even. So to end up with the blank or the 16 in the bottom right corner, it's definitely an even number of moves.

  54. Maria

    Definitely an even number of moves. So that means if we start from this configuration and we end up with the blank square in the 16 position, we can only rearrange this to correspond to an even permutation.

  55. Corey

    Alright, so to prove that this one is impossible, all we have to do now is check whether the permutation corresponding to this arrangement is even or odd. If it turns out to be odd, then we know we cannot reach it by these moves.

  56. Maria

    Okay, how do we do that, though? That looks like such a complicated thing to show.

  57. Corey

    Alright, so let's write out where we want to start from and where we want to get to. We want to start from this configuration, and we want to end in the permutation corresponding to that arrangement that starts with 15.

  58. Maria

    So 16 is going to end up in the same place, but all the other numbers have been rearranged. Let's construct a sequence of transpositions that is going to take this permutation to that permutation. This is actually not too hard.

  59. Corey

    So we have to switch 15 and 1, 14 and 2, 13 and 3, 4 and 12, 5 and 11, 6 and 10, and 7 and 9. If you make all those switches, then you'll get 15 first, 14, 13, 12. You'll get it in this order.

  60. Maria

    Of course, you can't make that switch in the puzzle game quite so easily, can you? You can't do it in the puzzle game without cheating and taking the tiles out. Right, but we know that the sequence you would have to use in the puzzle game would have a different number of steps, but the parity would be the same.

  61. Corey

    So we only have to worry about parity. So if I can show that with this sequence the parity is wrong, then whatever sequence we could do there would also be wrong. These are the switches that will get us from there to there.

  62. Maria

    Well, how many of them are there? There's 1, 2, 3, 4, 5, 6, 7. So, odd. That's enough to tell you that it's impossible?

  63. Corey

    That's it. So that means we cannot get from the starting configuration in order to the ending configuration in reverse order with the blank square in the same place. Let's think about Sam Loyd's original nasty challenge.

  64. Maria

    Which was to take the original configuration and end up with a configuration where everything is the same except the last two are switched. So if we analyze this using our math superpowers that we've just acquired, we have to compare our starting configuration to the configuration where everything is the same, except I've switched these last two tile numbers, and 16 stays the same.

  65. Corey

    How many transpositions do we need to get from the starting one to the ending one? Well, all we need to do is switch 14 and 15. So it's the transposition (14,15). That's all we need. There's one of them - odd.

  66. Maria

    So that's odd, but we know from this little argument that we made if we start with the blank at the lower right and we end with the blank in the same place, 16 at the end, then the number of steps that we have to have performed to get from start to finish has to be even.

  67. Corey

    So there's no way to start there, end there, and do an odd number of steps. So no one won the thousand bucks.

  68. Maria

    No, so Sam Loyd kept his thousand bucks. So these other ones that this package says are possible or impossible, we've got to - we have to check all of them. We don't know which ones of those are possible or not.

  69. Corey

    Right, let's see if we think it's possible to end up with the arrangement where the numbers go around the board in a spiral, and now we end up with the blank over there. Let's see if this should be possible.

  70. Maria

    So we're starting from the standard starting configuration, so the blank starts in the bottom right. And we want to know, can we end up like this? What's the parity of the number of steps that it would take to get the blank from its starting to its ending position?

  71. Corey

    Well, it started in the bottom right. To get to where it is at the end of this configuration, we have to move one, two to the left and one up. So the number of steps has to have the same parity as three.

  72. Maria

    So the fancy math way of writing that is to say that the number of steps has to be 1 mod 2. In other words, odd. Yeah, odd. Okay. That's a very fancy way of saying odd!

  73. Corey

    Alright, alright. Let's write odd as well, write odd under it. Sorry, unnecessarily. Rather than 1 mod 2. Yeah, yeah. Okay. So it's odd. Whether this is possible or not then depends on whether the configuration corresponding to this, which is 1, 2, 3, 4, 12, 13, 14, 5, 11 (remember blank is 16), 15, 6, 10, 9, 8, 7, is that odd?

  74. Maria

    So this one, it's not as easy to draw a map in the same way there, but we can certainly figure out a path from the starting configuration to there. How are we going to do it? So we don't have to do anything about the first four. 12, 13, 14 in the starting configuration are over there. They all have to be moved to come after 1, 2, 3, 4.

  75. Corey

    So we can do that. Let's see. 12 would have to be switched with 11, then 10, then 9, then 8, then 7, then 6, then 5. So that's 1, 2, 3, 4, 5, 6, 7 hops. That would put the 12 in front of the 5. Then the 13 can come behind it, another 7 hops, and the 14 behind that, another 7.

  76. Maria

    We can get this much correct by doing we had to do seven hops for the 12, seven for the 13, and seven for the 14. So that's going to take 3 times 7. Odd, there's odd hops. Odd number so far. Okay, now 5 is in the right place as well, so we're good up to there.

  77. Corey

    We have to get 11 into the correct place behind the five. So that's going to take five hops. Now we're good up to 11. Now we need the 16, that's gonna be one, two, three, four, five, another six hops. Now we're good up to there.

  78. Maria

    15 into its correct position, that's going to take one, two, three, four, five hops. Nine, ten. That was another one. Now we've got 15. Six happens to be in its right position. So now we've got to just switch the last few. We've got to get 7, 8, 9, 10 into the order 10, 9, 8, 7.

  79. Corey

    Here we can - actually we can short-circuit things. We switch those two and those two - that will do the job. So that's another two that's odd. Don't even need to know the actual number. All we need to know is, is it even or odd. Here we have another 10 steps. That's even, so an even number plus an odd number is odd.

  80. Maria

    Good news! Because look up here. Good news. Right. Because that's what we wanted. Good news. That's gettable then. So let's do it. You can edit this. Mathematics wins.

  81. Corey

    Okay, I'm gonna make your prediction: the number of people on the YouTube video that write comments saying, "Oh, I just take the tiles out or I cheat" and things like that is going to be odd.

  82. Maria

    Odd, but not peculiar! Odd, and a lot of them. Elements here, which these are not quite Tetris because Tetris is four squares, these have five. So these are five squares. So these are all the possible ways you can put five squares together. If you were to stop right now, this is area 20. So if you were to stop right now, your score would be 20. That's your biggest, minus your smallest 4, your score would be 16.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent