A Java Pentominoes Solver using Knuth's Dancing Links Method

Pentominoes in Java, using Knuth's Dancing Links Method

Donald Knuth describes the Dancing Links method via the Pentominoes puzzle. Based upon his description, I've implemented the Dancing Links algorithm and have a demonstration application that solves the 3x20 pentominoes puzzle.

This puzzle is personally interesting because it was used as a plot device in Arthur C. Clarke's novel Imperial Earth. Over the years, I've applied various methods to the puzzle, summarized by the page here.

My approach uses a core implementation of Dancing Links that is also used in my Sudoku solver.

Most of the work in my Pentominoes solution is to eliminate piece-positions that have no value. While the implementation of these heuristics seems complex, they reduce the solution space greatly: without the heuristics, my code ran for several hours before all solutions were produced. With the heuristics, runtime was reduced to about twelve seconds (on an 800MHz PowerBook G4 running Java 1.4.2).

The source code can be found in this jar file. Use the "jar" command to unpack the source files, then use standard methods to compile the code. When you run the BuildPentosTable class, the eight solutions (including rotations) will be printed quickly.

If your browser supports Java applets, there is a graphical display of the 3x20 pentominoes puzzle available as well.

questions, comments, etc to chesnutt at gmail dot com

return to Stan Chesnutt's webpage

$Header: /home/cvs/htdocs/stan/pentos_dancing_links.html,v 1.3 2007/01/01 05:24:38 chesnutt Exp $