solution algorithm to the sam loyd (n2-1) puzzle · kyle a. bishop dustin l. madsen solution...

48
Solution Algorithm to the Sam Loyd (n 2 - 1) Puzzle Kyle A. Bishop Dustin L. Madsen December 15, 2009 Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n 2 - 1) Puzzle

Upload: others

Post on 11-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Solution Algorithm to the Sam Loyd (n2 − 1)Puzzle

Kyle A. BishopDustin L. Madsen

December 15, 2009

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 2: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Introduction

The Sam Loyd puzzle was a 4× 4 grid invented in the 1870’s withnumbers 0 through 15 on each of the grid tiles with the 15 tilebeing an open space.

0 1 2 3

4 5 6 7

8 9 10 11

12 13 14 15

Sam Loyd 4× 4 Puzzle

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 3: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Introduction

I The puzzle was scrambled using the empty space and wassolved when the user brought it back to the original 1 through15 configuration.

Start State → Goal State

4 7 8 10

14 3 15 9

0 1 2 5

12 6 11 13

0 1 2 3

4 5 6 7

8 9 10 11

12 13 14 15

I The scrambled puzzle is called the start state and the solutionpuzzle is called the goal state.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 4: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Solvability

I When attempting any Sam Loyd puzzle, solvability must firstbe checked in order to determine if the puzzle has a solutionor not.

I This is done by first checking the amount of permutations toget from the start state of the puzzle to the goal state.

I Second, the distance the open space is from its goal stateposition is found.

I If the sum of these two numbers is even, the puzzle issolvable; odd, then the puzzle is unsolvable.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 5: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations

I Each permutation is defined as the act of replacing any tile ina given position for that position’s goal state tile.

I When actually playing the puzzle, each individual piece canonly be exchanged with the empty space to achieve movementtowards the goal state. When determining the evenness of theboard to check solvability, this restriction is lifted.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 6: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations

I A permutation cycle begins by first moving the tile in the 0position into its goal state position.

I The tile which was moved off the board is then put into itsgoal state position and so on.

I A permutation cycle is complete when there are no more tilesleft off the board to be moved into its goal state position.

I If there is no tile currently in a given position for the goalstate tile to replace, this is not considered a permutation.

I The next permutation cycle begins with the next position notholding its goal state tile.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 7: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I Using a simple 3× 3 puzzle, checking evenness can be shown.8 will represent the open space.

6 3 0

1 8 4

2 5 7

Start State

I It is easier to perform the permutations by writing the puzzleinto a list form going by rows.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 8: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Start State

6 3 0

1 8 4

2 5 7

I Rewriting the above start state into list form:

6 3 0 1 8 4 2 5 7

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 9: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I For this example, the 6 is currently in the 0 position and willbe the first piece moved.

6 3 0 1 8 4 2 5 7

I Blue squares will represent tiles which are being moved totheir goal state.

I Red squares will represent tiles which are in their goal stateposition.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 10: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I The 6 moves into the position held by the 2, and the 2 is thenext tile to be placed into its goal state position.

6 3 0 1 8 4 2 5 7

3 0 1 8 4 6 5 7

2

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 11: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I The 2 moves into the position held by the 0, and the 0 is thenext tile to be placed into its goal state position.

3 0 1 8 4 6 5 7

2

0

3 2 1 8 4 6 5 7

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 12: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I The 0 is placed into the empty tile at the 0 position which wasoriginally occupied the 6. This will end the first permutationcycle. These permutations are recorded for use later.

0

3 2 1 8 4 6 5 7

0 3 2 1 8 4 6 5 7

I 1st cycle : [ 6 , 2 , 0 ]

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 13: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I Now that all pieces are back onto the board, the secondpermutation cycle will begin.

I The next tile to be moved is the 3 held in the 1 position.

0 3 2 1 8 4 6 5 7

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 14: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I The 3 is put into its goal state position held by the 1 tile.

0 3 2 1 8 4 6 5 7

0 2 3 8 4 6 5 7

1

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 15: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I The 1 tile is placed into its goal state position which was heldby the 3, ending the second permutation cycle.

0 2 3 8 4 6 5 7

1

0 1 2 3 8 4 6 5 7

I 1st cycle: [ 6 , 2 , 0 ]I 2nd cycle: [ 3 , 1 ]

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 16: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I Now that all pieces are back onto the board, the thirdpermutation cycle will begin.

I The next tile to be moved is the 8 held in the 4 position.

0 1 2 3 8 4 6 5 7

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 17: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I The 8 replaces the 7.

0 1 2 3 8 4 6 5 7

0 1 2 3 4 6 5 8

7

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 18: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I The 7 replaces the 5.

0 1 2 3 4 6 5 8

7

5

0 1 2 3 4 6 7 8

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 19: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I The 5 replaces the 4.

5

0 1 2 3 4 6 7 8

0 1 2 3 5 6 7 8

4

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 20: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Example

I The 4 is then the final piece to be moved and goes into theempty space which was occupied by the 8 tile

I This ends the third and final permutation cycle.

0 1 2 3 5 6 7 8

4

0 1 2 3 4 5 6 7 8

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 21: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Sum

Now that the puzzle is in its goal state, the sum of permutations isfound.

I 1st cycle: [ 6 , 2 , 0 ]

I 2nd cycle: [ 3 , 1 ]

I 3rd cycle: [ 8 , 7 , 5 , 4 ]

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 22: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Sum

I Recall that each permutation is the act of replacing one tilefor another.

I Because of this, the last tile in each cycle is not counted as apermutation as it did not replace a tile when being placed intoits goal state position.

I With this in mind, each cycle will have n − 1 permutations,where n is the number of tiles in the cycle.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 23: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Permutations Sum

Summing the permutations of each cycle:

I 1st cycle: [ 6 , 2 , 0 ] → 2 Permutations

I 2nd cycle: [ 3 , 1 ] → 1 Permutations

I 3rd cycle: [ 8 , 7 , 5 , 4 ] → 3 Permutations

Sum = 6 Permutations

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 24: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Solvability

I Now that the sum of permutations has been recorded, thedistance of the open space from its goal state position isfound.

I We look at the original start state puzzle in order todetermine this distance.

I The distance is known as the Manhattan Distance.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 25: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Manhattan Distance

I The Manhattan distance is the amount of movementsrequired to move the open space from its start state positioninto its goal state position, the bottom right corner.

6 5 4 3

5 4 3 2

4 3 2 1

3 2 1 0

4× 4 Manhattan Distance Matrix

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 26: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Manhattan Distance

6 3 0

1 8 4

2 5 7

4 3 2

3 2 1

2 1 0

I Comparing the original sample start state with a 3× 3Manhattan Distance matrix, we can see that the ManhattanDistance is 2.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 27: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Manhattan Distance

I The sum of permutations and Manhattan distance is 8.

I Because this sum is even, the example puzzle is solvable.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 28: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Puzzle Solution Algorithm

I Solvable puzzles are solved using the Parberry divide andconquer algorithm.

I This algorithm repeatedly reduces the n × n puzzle into an(n − 1)× (n − 1) puzzle.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 29: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Puzzle Solution Algorithm

To solve any n × n puzzle using the Parberry divide and conqueralgorithm:

I Step 1: Place tiles 0 to (n − 1) in top row.

I Step 2: Place tiles n, (n × 2), . . . [n × (n − 1)] in leftmostcolumn.

I Step 3: Solve for (n − 1)× (n − 1) puzzle.

I Once the puzzle is reduced to 2× 2, the final four tiles arerotated into place.

A 4× 4 example will be presented:

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 30: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Puzzle Solution Algorithm

I Step 1: Place tiles 0 to (n − 1) in top row.

I Tiles: 0, 1, 2, 3.

12 5 7 0

2 11 4 9

6 8 14 13

1 10 3 15

0 1 2 3

6 4 11 15

7 13 10 8

12 14 5 9

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 31: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Puzzle Solution Algorithm

I Step 2: Place tiles n, (n × 2), . . . [n × (n − 1)] in leftmostcolumn.

I Tiles: 4, 8, 12

0 1 2 3

6 4 11 15

7 13 10 8

12 14 5 9

0 1 2 3

4 6 11 15

8 13 10 7

12 14 5 9

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 32: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Puzzle Solution Algorithm

I Step 3: Solve for (n − 1)× (n − 1) puzzle.

0 1 2 3

4 6 11 15

8 13 10 7

12 14 5 9

0 1 2 3

4 6 11 15

8 13 10 7

12 14 5 9

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 33: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Puzzle Solution Algorithm

I Continuing the algorithm, 3× 3→ 2× 2 :

0 1 2 3

4 6 11 15

8 13 10 7

12 14 5 9

0 1 2 3

4 5 6 7

8 9 14 10

12 13 15 11

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 34: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Puzzle Solution Algorithm

I The 2× 2 puzzle then needs to be rotated into the final goalstate positions:

0 1 2 3

4 5 6 7

8 9 14 10

12 13 15 11

0 1 2 3

4 5 6 7

8 9 14 10

12 13 15 11

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 35: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Puzzle Solution Algorithm

I 2× 2 puzzle is rotated into goal state positions:

0 1 2 3

4 5 6 7

8 9 14 10

12 13 15 11

0 1 2 3

4 5 6 7

8 9 10 11

12 13 14 15

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 36: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Tile Movements

I In order to perform the Parberry divide and conqueralgorithm, specific tile movements are required.

I Each tile movement will depend upon its current locationrelative to its goal state position.

I The tile being moved is called the target tile.

I The goal state position is called the home location.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 37: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Tile Movements

There are four cases to consider when performing movement oftiles:

I Case 1: Target tile is to the left of its home column.

I Case 2: Target tile is on its home column.

I Case 3: Target tile is to the right of its home column,underneath home right diagonal.

I Case 4: Target tile is to the right of its home column, on orabove the home right diagonal.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 38: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Tile Movements

H

H HD

L H R HD

L H R HD

L H R

H

H

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 39: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Tile Movements

I Case 1: Target tile is to the left of it’s home column.

H

2

H

L

L

L 2

I The target is placed onto the left diagonal and moved into itshome position.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 40: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Tile Movements

I Case 2: Target tile is on it’s home column.

H

2

H

2

I The target is moved up and along its home column.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 41: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Tile Movements

I Case 3: Target tile is to the right of its home column,underneath home right diagonal.

H

HD

HD

1

H

R

R

1 R

I The target is placed onto the right diagonal beneath the homeposition and moved into its home position.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 42: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Tile Movements

I Case 4: Target tile is to the right of its home column, on orabove the home right diagonal.

H 1

H HD

H HD

H

H 1

H HD

H HD

H

I The target is placed onto the home diagonal and moved intoits home position

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 43: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Corner Cases

I When filling in the last two tiles for every row and column, adifferent approach is taken.

0 1

2

3

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 44: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Corner Cases

I The n − 2 tile is placed into the n − 1 position.

0 1 2

3

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 45: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Corner Cases

I The n − 1 tile is placed below the n − 2 tile.

0 1 2

3

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 46: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Corner Cases

I The tiles are then rotated as in the final step of the Parberrydivide and conquer algorithm.

0 1 2

3

0 1 2 3

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 47: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

Special Board Configuration

I Sometimes when performing the solution to a puzzle thissituation may arise.

0 1 3 2

I This can not be solved by the methods previously presented.

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle

Page 48: Solution Algorithm to the Sam Loyd (n2-1) Puzzle · Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 1) Puzzle Permutations Example I The 6 moves into the position

References

Hayes, Richard The Sam Loyd 15-Puzzle

Kyle A. Bishop Dustin L. Madsen Solution Algorithm to the Sam Loyd (n2 − 1) Puzzle