Pearl Puzzles are NP-complete

Erich Friedman
Stetson University, DeLand, FL 32723



Pearl puzzles are pencil and paper puzzles which originated in Japan [11]. Each puzzle consists of a grid of squares, some of which contain white or black pearls. The goal is to find a closed, non-intersecting path passing through every pearl so that a) the path turns at every black pearl, but does not turn immediately before or after, and b) the path does not turn at any white pearl, but does turn immediately before or after. An example of a Pearl puzzle and its solution are shown in Figure 1.

Figure 1. A Pearl puzzle (left) and its solution (right)

We will show that the question of whether or not a given Pearl puzzle has a solution is NP-complete. To do so, we construct Pearl puzzles which correspond to arbitrary cubic planar graphs. The Pearl puzzle we construct will have a solution if and only if the corresponding graph has a Hamiltonian circuit. Since the problem of determining whether or not a cubic planar graph has a Hamiltonian circuit is known to be NP-complete [8, 9], this will show that Pearl puzzles are NP-hard. We complete the proof by verifying that a solution to a Pearl puzzle can be checked in polynomial time. Similar approaches to proving puzzles are NP-complete are taken in [1-3, 5-7, 10, 12-15].


The Construction

To build a Pearl puzzle that corresponds to a cubic planar graph G, we first draw a rectilinear realization G* of G. That is, G* is a drawing of G with all edges made of horizontal and vertical line segments. For example, the cubic graph on the left in Figure 2 has the rectilinear realization to its right.

Figure 2. A graph G (left) and a rectilinear realization G* (right)

The Pearl puzzle we construct will use only white pearls. Using these pearls, we build walls that can be arranged to form a network of rooms, separated by passagways. The passageways will correspond to the edges of G*, and some of the rooms will correspond to the vertices of G*.

To do this, note that when n 3, there are only two local solutions of a 2 x n rectangle of white pearls (see Figure 3). When a horizontal rectangle is diagonally adjacent to a vertical rectangle, there is only one possible local solution. Therefore we can string together horizontal and vertical rectangles to make walls of white pearls that curve that have a unique local solution.

Figure 3. The two local solutions of a rectangle of pearls

Inside each face of G*, including the infinite face, we build a wall unit. A simple wall unit is shown in Figure 4. We have great flexibility in how these wall units are created. See Figure 5 for a more complicated wall unit with a concave wall and path endpoints on a side of the unit. Notice that the solution loops in Figures 4 and 5 must continue away from the center of the wall unit.

Figure 4. Solution of a simple wall unit

Figure 5. Solution for a more complicated wall unit

These wall units will be placed next to each other to form passageways corresponding to the edges of G*. There will be 3 vacant squares between rows of pearls, which allows a single path to pass between them once we account for the zig-zagging solution to the wall unit. Small blank areas called rooms are created at each corner or intersection of the hallways (see Figure 6).

Figure 6. Walls units forming passageways (shown in dark gray) and rooms (shown in light gray)

In each room corresponding to a vertex of G*, we also place a single white pearl so that it does not touch any other pearls. This makes any solution to the puzzle visit each room corresponding to a vertex at least once. Since G* is a cubic graph and the passageways are only one unit wide, a room can not be visited again once the path leaves it. The endpoints of the path for each wall unit should be placed in a room corresponding to a vertex of G* to ensure that this wall unit is added to the solution loop when that room is visited by the loop. Therefore the Pearl puzzle we have constructed has a solution if and only if the corresponding graph has a Hamiltonian circuit. For example, for the graph in Figure 2, see Figure 7 for such a puzzle and Figure 8 for its solution.

Figure 7. A Pearl puzzle that corresponds to the graph in Figure 2.

Figure 8. A solution to the Pearl puzzle in Figure 7.


Polynomial Mapping and Checking

We know from [4] that a planar graph with n vertices can be realized using O(n2) area, so the mapping we have constructed from planar graphs to Pearl puzzles is polynomial. Furthermore, to check a candidate loop as a solution to a Pearl puzzle, we need to verify that the loop passes though each pearl in accordance with the rules, and that it does not intersect itself. The first of these is O(n2), since there are at most O(n2) pearls. The second is O(n4), since there are at most O(n2) line segments in the solution, and it suffices to check every pair of them. This completes the proof that Pearl puzzles are NP-complete.



[1] T. C. Biedl, E. D. Demaine, M. L. Demaine, R. Fleischer, L. Jacobsen, and J. I. Munro, "The Complexity of Clickomania". preprint.
[2] J. Culberson, "Sokoban is PSPACE complete." Proc. Internet Conf. Fun with Algorithms (1998), N. S. E. Lodi, L. Pagli, Ed., Carelton Scientific, 65-76.
[3] E. D. Demaine and M. Hoffman, "Pushing blocks is NP-complete for non-crossing solution paths". Proc. 13th Canad. Conf. Comput. Geom. (2001), 65-68.
[4] H. de Fraysseix, J. Pach, and R. Pach, and R. Pollack, "How to Draw a Planar Graph on a Grid". Combinatorica, 10 (1990), 41-51.
[5] E. Friedman, "Corral Puzzles are NP-complete". preprint.
[6] E. Friedman, "Cubic is NP-complete". preprint.
[7] E. Friedman, "Spiral Galaxies Puzzles are NP-complete". preprint.
[8] M.R. Garey and D.S. Johnson, Computers and Intractibility: A Guide to the Theory of NP-Completeness. W.H. Freeman, 1979.
[9] M.R. Garey, D.S. Johnson, and R.E. Tarjan, "The Planar Hamiltonian Circuit Problem is NP-Complete". SIAM J. Comput. (1976) 704-714.
[10] R. Kaye, "Minesweeper is NP-complete". Mathematical Intelligencer, 22 (2000) 9-15.
[11] Nikoli, 91 (2000).
[12] D. Ratner and M. Warmuth, "Finding a shortest solution for the n x n extension of the 15-puzzle is intractable". J. Symb. Comp. 10 (1990) 111-137.
[13] S. Takahiro, "The Complexities of Puzzles, Cross Sum, and Their ASPs". preprint.
[14] Y. Takayuki, "On the NP-completeness of the Slither Link Puzzle". IPSJ SIGNotes ALgorithms (2000).
[15] N. Ueda and T. Nagao, "NP-completeness Results for Nonogram via Parsimonious Reductions". preprint.