![]() Volume 9, Issue 3 Articles Tricks of the Trade In and Out Trott's Corner New Products New Publications Calendar News Bulletins New Resources Letters Classifieds Download This Issue Editorial Policy Staff and Contributors Submissions Subscriptions Advertising Back Issues Contact Information |
Polyominoes and Related Families
PolyominoesThe straightforward approach presented in the previous section has many disadvantages. The representation of polyominoes as 0-1 matrices is wasteful because they are very sparse. In this section we consider a polyomino to be a list of unit squares, where a square is specified by the Cartesian coordinates of its bottom-left vertex; further, these coordinates will be encapsulated as complex numbers. So, a polyomino will be a list of Gaussian integers; that is, complex numbers having integral real and imaginary parts. We thus define the following type.
In this definition we cannot use the pattern _Complex.. because only numbers with nonzero imaginary parts have head Complex. To determine whether two figures are equivalent, we consider the action of the dihedral group If we were using a matrix m to describe the positions of the squares forming a polyomino, we could perform a 90° rotation with Reverse[Transpose[m]] and a reflection with Transpose[m]. The following functions act on a given polyomino p; rot and ref correspond to the transformations r and f. The function cyclic computes the list of the rotations of p and is used in the construction of
The function draw generates the graphical object with an optional second argument specifying the plot range. Note also the change in the representation of a polyomino; the function canonical places the polyomino in the first quadrant touching both axes. Here is an example.
The function allpieces computes all eight equivalent figures (or less for some polyominoes).
The following incremental method generates all n-ominoes. Having generated the set of all
We can now compare the time taken to generate all pentominoes with the time it took in the previous section. Because Mathematica uses dynamic programming to retain the generated n-ominoes, the time it takes to recompute old values will only amount to how long it takes to retrieve them and hence would be negligible. So for a fair comparison, we have to start anew so that all previous values are cleared. Let us restart the Mathematica kernel and evaluate the following after all initialization cells are evaluated.
We can now obtain the number of free n-ominoes (free meaning equivalent under rotation and reflection) ([5, 6] seq. A000105).
As an illustration, let us generate all 108 heptominoes, because it is not until
We can also obtain the one-sided (no reflections allowed) or "chiral" polyominoes by running the following cell, which redefines function allPieces, rerunning the previous function polyominoes, and computing the table as was done before ([5, 6] seq. A000988). At the end of the generation of this table, we have to recover the original definition of allPieces because it is needed in the next section. The easiest way is to restart the Mathematica kernel, evaluate the initialization cells, and continue with the cells in the next section.
|
||||||||
About Mathematica | Download Mathematica Player © 2005 Wolfram Media, Inc. All rights reserved. |