Knuth D. The Art of Computer Programming Vol 4. Pre Fasc 5c 2019
Knuth D. The Art of Computer Programming Vol 4. Pre Fasc 5c 2019
KNUTH
THE ART OF
COMPUTER PROGRAMMING
VOLUME 4 PRE-FASCICLE 5C
DANCING
LINKS
▲
ADDISON-WESLEY ▼▼
July 26, 2019
Internet
Stanford GraphBase
MMIX
PREFACE
This booklet contains draft material that I’m circulating to experts in the
field, in hopes that they can help remove its most egregious errors before too
many other people see it. I am also, however, posting it on the Internet for
courageous and/or random readers who don’t mind the risk of reading a few
pages that have not yet reached a very mature state. Beware: This material
has not yet been proofread as thoroughly as the manuscripts of Volumes 1, 2, 3,
and 4A were at the time of their first printings. And alas, those carefully-checked
volumes were subsequently found to contain thousands of mistakes.
Given this caveat, I hope that my errors this time will not be so numerous
and/or obtrusive that you will be discouraged from reading the material carefully.
I did try to make the text both interesting and authoritative, as far as it goes.
But the field is vast; I cannot hope to have surrounded it enough to corral it
completely. So I beg you to let me know about any deficiencies that you discover.
To put the material in context, this portion of fascicle 5 previews Section
7.2.2.1 of The Art of Computer Programming, entitled “Dancing links.” It
develops an important data structure technique that is suitable for backtrack
programming, which is the main focus of Section 7.2.2. Several subsections
(7.2.2.2, 7.2.2.3, etc.) will follow.
* * *
411, 414, 416, 425, 428, 445. Are those problems still open? Please inform me if Pemantle
Pittel
you know of a solution to any of these intriguing questions. And of course if no Randall
solution is known today but you do make progress on any of them in the future, Katz
whirl
I hope you’ll let me know. Jelliss
I urgently need your help also with respect to some exercises that I made Beluhov
Dalgety
up as I was preparing this material. I certainly don’t like to receive credit for Engelhardt
things that have already been published by others, and most of these results are Gessel
Huang
quite natural “fruits” that were just waiting to be “plucked.” Therefore please Postl
tell me if you know who deserves to be credited, with respect to the ideas found Shortz
Sicherman
in exercises 1, 2, 4, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 32, 34, 36, 54, 62, Stanley
66, 68, 69, 71, 83, 84, 85, 94, 95, 96, 97, 98, 99, 100, 109, 114, 117, 118, 125, FGbook
137(b,c,d), 140, 141(b), 142, 144, 145, 146, 147, 148, 152, 157, 158, 160, 162,
169, 170, 171, 175, 176, 177, 178, 184, 185, 187, 188, 191, 197, 201, 207, 212,
217, 249, 273, 275, 278, 280, 289, 294, 300, 301, 303(d), 307, 308, 309, 310, 311,
313, 317, 319, 320, 321, 328, 329, 330, 331, 339, 342, 346(a,b,c), 362, 363, 364,
365, 366, 367, 370, 371, 373, 376, 381, 383, 384, 386, 387, 392, 393, 394, 395,
401, 405, 411, 413, 424, 427, 429, 434, 438, 442, 443, 444, 445, 446, 448, 449.
Furthermore I’ve cited unpublished work of Pemantle, Pittel, Randall, and Katz
in answers 39, 262, and 394. Have any of those results ever appeared in print,
to your knowledge?
* * *
Special thanks are due to George Jelliss for answering dozens of historical queries,
as well as to Nikolai Beluhov, James Dalgety, Matthias Engelhardt, Ira Gessel,
Wei-Hwa Huang, Helmut Postl, Will Shortz, George Sicherman, Richard Stanley,
and . . . for their detailed comments on my early attempts at exposition. And
I want to thank numerous other correspondents who have contributed crucial
corrections.***
***
I happily offer a “finder’s fee” of $2.56 for each error in this draft when it is first
reported to me, whether that error be typographical, technical, or historical.
The same reward holds for items that I forgot to put in the index. And valuable
suggestions for improvements to the text are worth 32c/ each. (Furthermore, if
you find a better solution to an exercise, I’ll actually do my best to give you
immortal glory, by publishing your name in the eventual book:-)
In the preface to Volume 4B I plan to introduce the abbreviation FGbook for
my book Selected Papers on Fun & Games (Stanford: CSLI Publications, 2011),
July 26, 2019
PREFACE v
During the years that I’ve been preparing Volume 4, I’ve often run across
basic techniques of probability theory that I would have put into Section 1.2
of Volume 1 if I’d been clairvoyant enough to anticipate them in the 1960s.
Finally I realized that I ought to collect most of them together in one place,
near the beginning of Volume 4B, because the story of these developments is too
interesting to be broken up into little pieces scattered here and there.
Therefore this volume begins with a special section entitled “Mathematical
Preliminaries Redux,” and future sections use the abbreviation ‘MPR’ to refer
to its equations and its exercises.
* * *
Several exercises involve the lists of English words that I’ve used in preparing
examples. You’ll need the data from
http://www-cs-faculty.stanford.edu/~knuth/wordlists.tgz
if you have the courage to work those exercises.
vi
July 26, 2019
7.2.2.1 DANCING LINKS 1
At this point the conventional wisdom is to recycle node X, making it available for
reuse in another list. We might also want to tidy things up by clearing LLINK(X)
and RLINK(X), so that stray pointers to nodes that are still active cannot lead
to trouble. (See, for example, Eq. 2.2.5-(4), which is the same as (i) except
that it also says ‘AVAIL ^ X’.) By contrast, the dancing-links trick resists any
urge to do garbage collection. In a backtrack application, we’re better off leaving
LLINK(X) and RLINK(X) unchanged. Then we can undo operation (i) by simply
setting
RLINK(LLINK(X)) ^ X, LLINK(RLINK(X)) ^ X. (2)
For example, we might have a 4-element list, as in 2.2.5-(г):
List head
(3)
Subsequent deletion of the final element, then the first, will leave us with this: undelete
exact covering—
set partitioning, see exact covering
0s and 1s
(4) sparse
options
items
The list is now empty, and its links have become rather tangled. (See exercise 1.)
But we know that if we proceed to backtrack at this point, using (2) to undelete
elements 1, 4, 2, and 3 in that order, we will magically restore the initial state (3).
The choreography that underlies the motions of these pointers is fun to watch,
and it explains the name “dancing links.”
Exact cover problems. We will be seeing many examples where links dance
happily and efficiently, as we study more and more examples of backtracking.
The beauty of the idea can perhaps be seen most naturally in an important
class of problems known as exact covering: We’re given an M x N matrix A of
0s and 1s, and the problem is to find a subset of rows whose sum is exactly 1 in
every column. For example, consider the 6 x 7 matrix
0 0 1 0 1 0 0
1 0 0 1 0 0 1
0 1 1 0 0 1 0
A= . (5)
1 0 0 1 0 1 0
0 1 0 0 0 0 1
0 0 0 1 1 0 1
Each row of A corresponds to a subset of a 7-element universe. A moment’s
thought shows that there’s only one way to cover all seven of these columns with
disjoint rows, namely by choosing rows 1, 4, and 5. We want to teach a computer
how to solve such problems, when there are many, many rows and many columns.
Matrices of 0s and 1s appear frequently in combinatorial problems, and
they help us to understand the relations between problems that are essentially
the same although they appear to be different (see exercise 5). But inside a
computer, we rarely want to represent an exact cover problem explicitly as a two
dimensional array of bits, because the matrix tends to be extremely sparse: There
normally are very few 1s. Thus we’ll use a different representation, essentially
with one node in our data structure for each 1 in the matrix.
Furthermore, we won’t even talk about rows and columns! Some of the exact
cover problems we deal with already involve concepts that are called “rows” and
“columns” in their own areas of application. Instead we will speak of options
and items : Each option is a set of items; and the goal of an exact cover problem
is to find disjoint options that cover all the items.
For example, we shall regard (5) as the specification of six options involving
seven items. Let’s name the items a, b, c, d, e, f, g; then the options are
The first, fourth, and fifth options give us each item exactly once.
July 26, 2019
7.2.2.1 dancing links: exact cover problems 3
One of the nicest things about exact cover problems is that every tentative recursive algorithm
covering an item
choice we make leaves us with a residual exact cover problem that is smaller — active list of items
often substantially smaller. For example, suppose we try to cover item a in (6) LLINK
by choosing the option ‘a d g’: The residual problem has only two options, RLINK
ULINK
‘c e’ and ‘b c f ’, (7) DLINK
TOP
because the other four involve the already-covered items. Now it’s easy to see
that (7) has no solution; therefore we can remove option ‘a d g’ from (6). That
leaves us with only one option for item a, namely ‘a d f ’. And its residual,
‘c e’ and ‘b g’, (8)
gives us the solution we were looking for.
Thus we’re led naturally to a recursive algorithm that’s based on the primi
tive operation of “covering an item”: To cover item i, we delete all of the options
that involve i, from our database of currently active options, and we also delete i
from the list of items that need to be covered. The algorithm is simply this:
• Select an item i that needs to be covered; but terminate
successfully if none are left (we’ve found a solution).
• If no active options involve i, terminate unsuccessfully
(9)
(there’s no solution). Otherwise cover item i.
• For each just-deleted option O that involves i, one at a time,
cover each item j = i in O, and solve the residual problem.
(Everything that’s covered must later be uncovered, of course, as we’ll see.)
Interesting details arise when we flesh out this algorithm and look at ap
propriate low-level mechanisms. There’s a doubly linked “horizontal” list of all
items that need to be covered; and each item also has its own “vertical” list of all
the active options that involve it. For example, the data structures for (6) are:
11
15
15 19 (lo)
19 23
23 26
26 30
(In this diagram, doubly linked pointers “wrap around” at the dotted lines.) The
horizontal list has LLINK and RLINK pointers; the vertical lists have ULINK and
DLINK. Nodes of each vertical list also point to their list header via TOP fields.
July 26, 2019
4 combinatorial searching (f5c: 26 Jul 2019 @ 2051) 7.2.2.1
The top row of diagram (10) shows the initial state of the horizontal item spacer nodes
list and its associated vertical headers. The other rows illustrate the six options LEN
of (6), which are represented by sixteen nodes within the vertical lists. Those
options implicitly form horizontal lists, indicated by light gray lines; but their
nodes don’t need to be linked together with pointers, because the option lists
don’t change. We can therefore save time and space by allocating them sequen
tially. On the other hand, our algorithm does require an ability to traverse each
option cyclically, in both directions. Therefore we insert spacer nodes between
options. A spacer node x is identified by the condition TOP(x) < 0; it also has
ULINK(x) = address of the first node in the option before x;
(11)
DLINK(x) = address of the last node in the option after x.
These conventions lead to the internal memory layout shown in Table 1.
First come the records for individual items; those records have NAME, LLINK, and
RLINK fields, where NAME is used in printouts. Then come the nodes, which have
TOP, ULINK, and DLINK fields. The TOP field is, however, called LEN in the nodes
that serve as item headers, because Algorithm X below uses those fields to store
the lengths of the item lists. Nodes 8, 11, 15, 19, 23, 26, and 30 in this example
are the spacers. Fields marked ‘ — ’ are unused.
Table 1
THE INITIAL CONTENTS OF MEMORY CORRESPONDING TO (6) AND (io)
i: 0 1 2 3 4 5 6 7
NAME(i): — a b c d e f g
LLINK(i): 7 0 1 2 3 4 5 6
RLINK(i): 1 2 3 4 5 6 7 0
x: 0 1 2 3 4 5 6 7
LEN(x): — 2 2 2 3 2 2 3
ULINK(x): — 20 24 17 27 28 22 29
DLINK(x): — 12 16 9 13 10 18 14
x: 8 9 10 11 12 13 14 15
TOP(x): 0 3 5 -1 1 4 7 -2
ULINK(x): — 3 5 9 1 4 7 12
DLINK(x): 10 17 28 14 20 21 25 18
x: 16 17 18 19 20 21 22 23
TOP(x): 2 3 6 -3 1 4 6 -4
ULINK(x): 2 9 6 16 12 13 18 20
DLINK(x): 24 3 22 22 1 27 6 25
x: 24 25 26 27 28 29 30
TOP(x): 2 7 -5 4 5 7 -6
ULINK(x): 16 14 24 21 10 25 27
DLINK(x): 2 29 29 4 5 7 —
OK, we’re ready now to spell out precisely what happens inside the com
puter’s memory when Algorithm X wants to cover a given item i:
Set p ^ DLINK(i). (Here p, l, and r are local variables.)
{ RLINK(l) ^ i, LLINK(r) ^ i.
Set p ^ ULINK(i).
While p = i, unhide(p), then set p ^ ULINK(p) and repeat.
Set q ^ p — 1, and repeat the following while q = p:
(14)
and (15) to undelete in precisely the reverse order of the way that we’d previously
used operation (1) inside (12) and (13) to delete. Furthermore, we’re able to do
this in place, without copying, by waltzing through the data structure at the
same time as we’re modifying it.
Algorithm X (Exact cover via dancing links). This algorithm visits all solutions
to a given exact cover problem, using the data structures just described. It also
maintains a list x0, x1, . . . , xT of node pointers for backtracking, where T is
large enough to accommodate one entry for each option in a solution.
X1. [Initialize.] Set the problem up in memory, as in Table 1. (See exercise 8.)
Also set N to the number of items, Z to the last spacer address, and l ^ 0.
X2. [Enter level l.] If RLINK(0) = 0 (hence all items have been covered), visit the
solution that is specified by x0x1 . . . xl-1 and go to X8. (See exercise 13.)
X3. [Choose i.] At this point the items i1, . . . , it still need to be covered, where
i1 = RLINK(0), ij+1 = RLINK(ij), RLINK(it) = 0. Choose one of them, and
call it i. (The MRV heuristic of exercise 9 often works well in practice.)
X4. [Cover i.] Cover item i using (12), and set xl ^ DLINK(i).
X5. [Try xl .] If xl = i, go to X7 (we’ve tried all options for i). Otherwise set
p ^ xl + 1, and do the following while p = xl: Set j ^ TOP(p); if j < 0,
set p ^ ULINK(p); otherwise cover(j) and set p ^ p +1. (This covers the
items = i in the option that contains xl.) Set l ^ l + 1 and return to X2.
X6. [Try again.] Set p ^ xl — 1, and do the following while p = xl: Set j ^
TOP(p); if j < 0, set p ^ DLINK(p); otherwise uncover(j) and set p ^ p — 1.
(This uncovers the items = i in the option that contains xl , using the reverse
of the order in X5.) Set i ^ TOP(xl), xl ^ DLINK(xl), and return to X5.
X7. [Backtrack.] Uncover item i using (14).
X8. [Leave level l.] Terminate if l = 0. Otherwise set l ^ l — 1 and go to X6. |
July 26, 2019
6 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
The reader is strongly advised to work exercise 11 now — yes, now, really! — Langford pairs
symmetry
in order to experience the dance steps of this instructive algorithm. When the n queens
procedure terminates, all of the links will be restored to their original settings.
We’re going to see lots of applications of Algorithm X, and similar algo
rithms, in this section. Let’s begin by fulfilling a promise that was made on
page 2 of Chapter 7, namely to solve the problem of Langford pairs efficiently
by means of dancing links.
The task is to put 2n numbers {1, 1, 2, 2, . . . , n, n} into 2n slots s1s2 . . . s2n,
in such a way that exactly i numbers fall between the two occurrences of i. It il
lustrates exact covering nicely, because we can regard the n values of i and the 2n
slots sj as items to be covered. The allowable options for placing the i’s are then
‘1 si S3’, ‘1 S2 S4’, ‘1 S3 S5’, ‘1 S4 S6’, ‘2 si S4’, ‘2 S2 S5’, ‘2 S3 S6’, ‘3 si S5’, ‘3 S2 S6’. (17)
An exact covering of all items is equivalent to placing each pair and filling each
slot. Algorithm X quickly determines that (17) has just two solutions,
^^{xij | 1 < i, j < n, i + j = s} < 1 for 1 < s < 2n; (19) slack variables
primary
secondary
^2{xij j 1 < i, j < n, i - j = d} < 1 for —n < d < n. (20)
N1
The inequalities in (19) and (20) can be changed to equalities by introducing
“slack variables” u2, . . . , u2n, v-n+1 , . . . , vn-1 , each of which is 0 or 1:
The order in which primary items appear in Algorithm X’s active list can order of primary items
organ-pip e order
have a significant effect on the running time, because the implementation of bitwise operations
step X3 in exercise 9 selects the first item of minimum length. For example, if diagonals
symmetry
we consider the primary items of the n queens problem in the natural order r1 , c1 , pairwise ordering
r2 , c2 , . . . , rn , cn, queens tend to be placed at the top and left before we try
to place them at the bottom and right. By contrast, if we use the “organ-pipe
order” r[_n/2J + 1, cLn/2J + 1, rLn/2J , cLn/2J, rLn/2J+2, c\n/2\+2, r\n/2\-1, c|n/2J-1>
. . . , (r1 or rn), (c1 or cn), the queens are placed first in the center, where they
prune the remaining possibilities more effectively. For example, the time needed
to find all 14772512 ways to place 16 queens is 76 G/< with the natural order,
but only 40 Gp, with the organ-pipe order.
These running times can be compared with 9 G^, which we obtained using
efficient bitwise operations with Algorithm 7.2.2W. Although that algorithm was
specially tuned, the general-purpose dancing links technique runs only five times
slower. Furthermore, the setup we’ve used here allows us to solve other problems
that wouldn’t be anywhere near as easy with ordinary backtrack. For example,
we can limit the solutions to those that contain queens on each of the 2 + 4l
longest diagonals, simply by regarding as and bd as primary items instead of
secondary, for |n +1 — s| < l and |d| < l. (There are 18048 such solutions when
n =16 and l = 4, found with organ-pipe order in 2.7 G^.)
We can also use secondary items to remove symmetry, so that most of the
solutions are found only once instead of eight times (see exercises 22 and 23).
The central idea is to use a pairwise ordering trick that works also in many other
situations. Consider the following family of 2m options:
It’s not hard to see that there are exactly m2+1 ways to cover both a and b,
namely to choose aj- and ek with 0 < j < k < m. For if we choose aj-, the
secondary items x0 through xj-1 knock out the options во, ..., ej-1.
This construction involves a total of m2+1 entries in the a options and
2m entries in the в options. But exercise 20 shows that it’s possible to achieve
pairwise ordering with only O(m log m) entries in both a’s and e’s. For example,
when m = 4 it produces the following elegant pattern:
ao = ‘a’; во = ‘b yi У2’;
a1 = ‘a y1’; в1 = ‘b y2’;
(26)
a2 = ‘a y2’; в2 = ‘b y3’;
a3 = ‘a y3 y2’; в3 = ‘b’.
Progress reports. Many of the applications of Algorithm X take a long time, node
search tree
especially when we’re using it to solve a tough problem that is breaking new backtree, see search tree
ground. So we don’t want to just start it up and wait with our fingers crossed, running time
threshold
hoping that it will finish soon. We really want to watch it in action and see how progress report
it’s doing. How many more hours will it probably run? Is it almost half done? author
mems
A simple amendment of step X2 will alleviate such worries. At the beginning queens problem
of that step, as we enter a new node of the search tree, we can test whether the completion ratio
ratio of completion
accumulated running time T has passed a certain threshold 0, which is initially
set to Д. If T > 0, we print a progress report and set 0 ^ 0 + Д. (Thus if
Д = to, we get no reports; if Д = 0, we see a report at each node.)
The author’s experimental program measures time in mems, so that he
can obtain machine-independent results; and he usually takes Д = 10 Gp. His
program has two main ways to show progress, namely a long form and a short
form. The long form gives full details about the current state of the search, based
on exercise 12. For example, here’s the first progress report that it displays when
finding all solutions to the 16 queens problem as described above:
Current state (level 15):
r8 c3 abba (4 of 16)
c8 a8 bn r0 (1 of 13)
r7 cb ai bj (7 of 10)
r6 c4 aabd (2 of 7)
3480159 solutions, 10000000071 mems, and max level 16 so far.
(The computer’s internal encoding for items is different from the conventions we
have used; for example, ‘r8 c3 ab ba’ stands for what we called ‘r9 c4 a13 b5’.
The first choice at level 0 was to cover item r8, meaning to put a queen into
row 9. The fourth of 16 options for that item has placed it in column 4. Then
at level 1 we tried the first of 13 ways to cover item c8, meaning to put a queen
into column 9. And so on. At each level, the leftmost item shown for the option
being tried is the one that was chosen in step X3 for branching.)
That’s the long form. The short form, which is the default, produces just
one line for each state report:
10000000071mu: 3480159sols, 4g 1d 7a 27 36 24 23 13 12 12 22 12 ... .19048
20000000111mu: 6604373sols, 7g cd 6a 88 36 35 44 44 24 11 12 22 .43074
30000000052mu: 9487419sols, bg cd 9a 68 37 35 24 13 12 12 .68205
40000000586mu: 12890124 sols, fg 6d aa 68 46 35 23 33 23 .90370
Altogether 14772512 solutions, 62296+45565990457 mems, 193032021 nodes.
Two-character codes are used to indicate the current position in the tree; for
example, ‘4g’ means branch 4 of 16, then ‘1d’ means branch 1 of 13, etc. By
watching these steadily increasing codes — it’s fun! — we can monitor the action.
Each line in the short form ends with an estimate of how much of the tree
has been examined, assuming that the search tree structure is fairly consistent.
For instance, ‘.19048’ means that we’re roughly 19% done. If we’re currently
working at level l on choice cl of tl , this number is computed by the formula
c0 - 1 + c1 - 1 + ... + cl - 1 +____ 1____ .
(27)
t0 t0t1 t0t1 . . . tl 2t0t1 . . . tl
July 26, 2019
10 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
Sudoku. A “sudoku square” is a 9 x 9 array that has been divided into 3 x 3 sudoku-
soduko: see sudoku
boxes and filled with the digits {1, 2, 3, 4, 5, 6, 7, 8, 9} in such a way that Garns
• every row contains each of the digits {1, 2, 3, 4, 5, 6, 7, 8, 9} exactly once; Number Place
Nikoli
• every column contains each of the digits {1, 2, 3, 4, 5, 6, 7, 8, 9} exactly once; pi, as random
• every box contains each of the digits {1, 2, 3, 4, 5, 6, 7, 8, 9} exactly once. 0-origin indexing
(Since there are nine cells in each row, each column, and each box, the words
‘exactly once’ can be replaced by ‘at least once’ or ‘at most once’, anywhere in
this definition.) Here, for example, are three highly symmetrical sudoku squares:
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 5 6 4 8 9 7 2 3 1
7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 9 7 8 3 1 2 6 4 5
2 3 4 5 6 7 8 9 1 2 3 1 5 6 4 8 9 7 6 4 5 9 7 8 3 1 2
(a) 5 6 7 8 9 1 2 3 4 ; (b) 5 6 4 8 9 7 2 3 1 ; (c) 7 8 9 1 2 3 4 5 6 • (28)
8 9 1 2 3 4 5 6 7 8 9 7 2 3 1 5 6 4 2 3 1 5 6 4 8 9 7
3 4 5 6 7 8 9 1 2 3 1 2 6 4 5 9 7 8 8 9 7 2 3 1 5 6 4
6 7 8 9 1 2 3 4 5 6 4 5 9 7 8 3 1 2 3 1 2 6 4 5 9 7 8
9 1 2 3 4 5 6 7 8 9 7 8 3 1 2 6 4 5 4 5 6 7 8 9 1 2 3
When the square has been only partially specified, the task of completing
it — by filling in the blank cells — often turns out to be a fascinating challenge.
Howard Garns used this idea as the basis for a series of puzzles that he called
Number Place, first published in Dell Pencil Puzzles & Word Games #16 (May
1979), 6. The concept soon spread to Japan, where Nikoli Inc. gave it the name
Su Doku , “Unmarried Numbers” in 1984; and eventually it went viral.
By the beginning of 2005, major newspapers had begun to feature daily sudoku
puzzles. Today, sudoku ranks among the most popular recreations of all time.
Every sudoku puzzle corresponds to an exact cover problem that has a
particularly nice form. Consider, for example, the following three instances:
3 1 3 3 1
4 1 5 9 1 4 4 1
2 6 5 3 1 5 5 9
5 8 9 9 2 6 4
7 9 3 2 2 6 3 5 (29)
3 8 4 6 5 3 1
2 6 4 3 5 8 4 6
3 8 9 7 5
3 2 7 9 5 8 3 4 9
(The clues in (29a) match the first 32 digits of n; but the clues in (29b) and (29c)
disagree with n after awhile.) For convenience, let’s number the rows, columns,
and boxes from 0 to 8. Then every sudoku square S = (sij ) corresponds naturally
to the solution of a master exact cover problem whose 9 • 9 • 9 = 729 options are
‘pij rik Cjk bxk for 0 < i, j < 9, 1 < k < 9, and x = 3[i/3j + [j/3\, (30)
and whose 4 • 9 • 9 = 324 items are pij, rik, cj-k, bxk. The reason is that option
(30) is chosen with parameters (i, j, k) if and only if sij = k. Item pij must be
covered by exactly one of the nine options that fill cell (i, j); item rik must be
covered by exactly one of the nine options that put k in row i; . . . ; item bxk
must be covered by exactly one of the nine options that put k in box x. Got it?
July 26, 2019
7.2.2.1 DANCING LINKS: SUDOKU 11
(3i)
The active list for item p00 , say, has options for values {7, 8, 9}; the active list for
item r02 has options for columns {5, 6, 7}; the active list for item c01 has options
for rows {4, 5, 6, 7}; and so on. (Indeed, sudoku experts tend to have charts like
this in mind, implicitly or explicitly, as they work.)
Aha! Look at the lonely ‘5’ in the middle! There’s only one option for p44 ; so
we can promote that ‘5’ to ‘5’. Hence we can also erase the other ‘5’s that appear
in row 4, column 4, or box 4. This operation is called “forcing a naked single.”
And there’s another naked single in cell (8, 4). Promoting this one from ‘4’
to ‘4’ produces others in cells (7, 4) and (8, 2). Indeed, if the items pij have been
placed first in step X1, Algorithm X will follow a merry path of forced moves
that lead immediately to a complete solution of (29 a), entirely via naked singles.
Of course sudoku puzzles aren’t always this easy. For example, (29 b) has
only 17 clues, not 32; that makes naked singles less likely. (Puzzle (29 b) comes
from Gordon Royle’s online collection of approximately 50,000 17-clue sudokus —
all of which are essentially different, and all of which have a unique completion
despite the paucity of clues. Royle’s collection appears to be nearly complete:
Whenever a sudoku fanatic encounters a 17-clue puzzle nowadays, that puzzle
almost invariably turns out to be equivalent to one in Royle’s list.)
A massive computer calculation, supervised by Gary McGuire and com
pleted in 2012, has shown that every uniquely solvable sudoku puzzle must
July 26, 2019
12 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
contain at least 17 clues. We will see in Section 7.2.3 that exactly 5,472,730,538 bitwise
McGuire
nonisomorphic sudoku squares exist. McGuire’s program examined each of them, Tugemann
and showed that comparatively few 16-clue subsets could possibly characterize it. Civario
naked singles
About 16,000 subsets typically survived this initial screening; but they too were hidden single
shown to fail. All this was determined in roughly 3.6 seconds per sudoku square,
thanks to nontrivial and highly optimized bitwise algorithms. [See G. McGuire,
B. Tugemann, and G. Civario, Experimental Mathematics 23 (2014), 190-217.]
The 17 clues of puzzle (29b) produce the following chart analogous to (31):
012345678
2 2 2 12 12 1 2 2
0 456
78
46
79
456
789 7
56
789
6 56
789 3 89
6 46
789
23 2 23 2 2 2
1 1 79
6 56
789
4 6
789
56
789 789
6
89 789
6
23 23 2 23 23 2
2 46
78
46
79
46
789 7
6 6
789
6
789
1 89
6
5
123 12 1 1 1 2 123 123
3 9 46
7
456
78 7
6 46
78
46
78
45
78
5
8
4
78
3 13 1 1 1 13 13 (32)
4 45
78
4
7
45
78 7
4
789
2 6 5
89
4
789
2 12 12 1 2 12 12
5 46
78
46
7
46
78 7
6 5 3 4
789 89
4
789
2 12 123 1 2 123 123
6 46
7 5 46
79 8 46
7
46
7 9
6
9
6
9
2 12 12 123 1 2 123
7 46 46 46
9 46 456 5
8 7 8
6
2 12 12 1 2 12
8 7
6 8 3 7
56
7
6
7
56 5
9
4 6
9
This one has 307 options remaining — more than twice as many as before. Also,
as we might have guessed, it has no naked singles. But it still reveals forced
moves, if we look more closely! For example, column 3 contains only one instance
of ‘3’; we can promote it to ‘3’, and kill all of the other ‘3’s in row 2 and box 1.
This operation is called “forcing a hidden single.”
Similarly, box 2 in (32) contains only one instance of ‘4’; and two other
hidden singles are also present (see exercise 47). These forced moves cause other
hidden singles to appear, and naked singles also arise soon. But after 16 forced
promotions have been made, the low-hanging fruit is all gone:
012345678
1 1
0 5 6
79 78
6 2 78
6 6
789 3 6
89
4
2 2 2
1 1 3 78
6 4 78
6
5 78
6
89 79
6
2 2 2 2
2 46
78
46
79
46
78 3 78
6 6
789
1 89
6
5
12 12 1 1 1 123 123
3 9 46
7
456
78 7
6 46
78
46
78
4
78
5
8 7
1 1 1 1 1 (33)
4 3 4
7
45
78 7 9 2 6 5
8 7
2 12 12 1 12 12
5 46
78
46
7
46
78 7
6 5 3 4
78 89 79
1 1 13 13
6 46
7 5 9 8 46
7
46
7
2 6 6
2 12 12 1
7 46 46 46
9 3 46
5 7 8
1 1
8 7
6 8 3 5 2 7
6 9 4 6
Algorithm X readily deduces (33) from (32), because it sees naked singles and naked pair
author
hidden singles whenever an item pij or rik or cjk or bxk has only one remaining secondary
option, and because its data structures change easily as the links dance. But
when state (33) is reached, the algorithm resorts to two-way branching, in this
case looking first at case ‘7’ of p16, then backtracking later to consider case ‘8’.
A human sudoku expert would actually glance at (33) and notice that there’s
a more intelligent way to proceed, because (33) contains a “naked pair”: Cells
(4, 3) and (4, 8) both contain the same two choices; hence we’re allowed to delete
‘1’ and ‘7’ wherever they appear elsewhere in row 4; and this will produce a naked
‘4’ in column 1. Exercise 49 explores such higher-order deductions in detail.
Fancy logic that involves pairs and triples might well be preferable for earth
lings, but simple backtracking works just fine for machines. In fact, Algorithm X
finds the solution to (29b) after exploring a search tree with just 89 nodes, the
first 16 of which led it directly to (33). (It spends about 250 kilomems initializing
the data structures in step X1, then 50 more kilomems to complete the task.
Much more time would have been needed if it had tried to look for complicated
patterns in step X3.) Here’s the solution that it discovers:
c33 b13 p23 r23 (1 of 1)
r13 c13 b03 p11 (1 of 1)
• • •
c42 b72 p84 r82 (1 of 1)
p16 r18 c68 b28 (2 of 2)
b27 p18 r17 c87 (1 of 1)
•••
p85 r81 c51 b71 (1 of 1)
After it selects the correct value for column 6 of row 1, the rest is forced.
The dancing links method actually cruises to victory with amazing speed, on
almost every known sudoku puzzle. Among several dozen typical specimens —
seen by the author since 2005 in newspapers, magazines, books, and webpages
worldwide, and subsequently presented to Algorithm X — roughly 70% were
found to be solvable entirely by forced moves, based on naked or hidden singles,
even though many of those puzzles had been rated ‘diabolical’ or ‘fiendish’ or
‘torturous’ ! Only 10% of them led to a search tree exceeding 100 nodes, and
none of the trees had more than 282 nodes. (See, however, exercise 52.)
It’s interesting to consider what happens when the algorithm is weakened,
so that its forced moves come only from naked singles, which are the easiest
deductions for people to make. Suppose we classify the items rik, cjk , and bxk
as secondary, leaving only pij as primary. (In other words, the specification will
require at most one occurrence of each value k, in every row, every column, and
every box, but it won’t explicitly insist that every k should be covered.) The
search tree for puzzle (29 b) then grows to a whopping 41,877 nodes.
Finally, what about puzzle (29 c)? That one has only 16 clues, so we know
that it cannot have a unique solution. But those 16 clues specify only seven of the
nine digits; they give us no way to distinguish 7 from 8. Algorithm X deduces,
with a 129-node search tree, that only two solutions exist. (Of course those two
are essentially the same; they’re obtainable from each other by swapping 7 ^ 8.)
July 26, 2019
14 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
Puzzlists have invented many intriguing variations on the traditional sudoku jigsaw sudoku puzzles
geometric sudoku
challenge, several of which are discussed in the exercises below. Among the best polyomino sudoku
are “jigsaw sudoku puzzles” (also known as “geometric sudoku,” “polyomino squiggly sudoku
author
sudoku,” “squiggly sudoku,” etc.), where the boxes have different shapes instead Harris
of simply being 3 x 3 subsquares. Consider, for example, pi as src
Gardner
GRAND TIME puzzle
United States Jigsaw Sudoku
Snyder
Thompson
Latin Squares
(b) . (34) Behrens
agriculture
In puzzle (34 a), which the author designed in 2017 with the help of Bob Harris,
one can see for instance that there are only two places to put a ‘4’ in the top row,
because of the ‘4’ in the next row. This puzzle is an exact cover problem just
like (30), except that x is now a more complicated function of i and j. Similarly,
Harris’s classic puzzle (34b) [Mathematical Wizardry for a Gardner (2009), 55
57] asks us to put the letters {G, R, A, N, D, T, I, M, E} into each row, column, and
irregularly shaped box. Again we use (30), but with the values of k running
through letters instead of digits. [Hint: Cell (0, 2) must contain ‘A’, because
column 2 needs an ‘A’ somewhere.] Puzzle (34 c), The United States Jigsaw
Sudoku, is a masterpiece designed and posted online by Thomas Snyder in 2006.
It brilliantly uses boxes in the shapes of West Virginia, Kentucky, Wyoming,
Alabama, Florida, Nevada, Tennessee, New York (including Long Island), and
Virginia — and its clues are postal codes! (See exercise 59.)
Jigsaw sudoku was invented by J. Mark Thompson, who began to publish
such puzzles in 1996 [GAMES World of Puzzles, #14 (July 1996), 51, 67] under
the name Latin Squares. At that time he had not yet heard about sudoku; one
of the advantages of his puzzles over normal sudoku was the fact that they can
be of any size, not necessarily 9 x 9. Thompson’s first examples were 6 x 6.
The solutions to puzzles of this kind actually have an interesting prehistory:
Walter Behrens, a pioneer in the applications of mathematics to agriculture,
wrote an influential paper in 1956 that proposed using such patterns in empirical
studies of crops that have been treated with various fertilizers [Zeitschrift fur
landwirtschaftliches Versuchs- und Untersuchungswesen 2 (1956), 176-193]. He
presented dozens of designs, ranging from 4 x 4 to 10 x 10, including
1 3 8 7 9 5 2 1 5 8 6 4 3 9 7 2
2 6 9 5 3 8 4 2 6 9 5 7 8 1 3 4
1 5 4 2 3 3 8 2 4 6 7 1 3 7 4 1 9 2 5 6 8
2 4 3 5 1 4 7 6 9 1 3 8 4 9 2 8 6 7 3 1 5
(a) 3 1 2 4 5 5 1 3 8 7 6 9 5 3 7 4 2 1 6 8 9 (35)
4 3 5 1 2 6 9 7 1 4 2 6 6 8 1 3 5 9 2 4 7
5 2 1 3 4 7 5 4 2 8 9 6 7 2 6 9 1 4 8 5 3
8 2 1 3 5 4 7 8 4 5 2 3 6 7 9 1
9 4 5 6 2 1 3 9 1 3 7 8 5 4 2 6
July 26, 2019
7.2.2.1 DANCING LINKS: POLYOMINOES 15
Notice that Behrens’s (35b) is actually 9 x 7, so its rows don’t exhibit all 9 Behrens
sudoku solution
possibilities. He required only that no treatment number be repeated in any row Ragaller
or column. Notice also that his (35 c) is actually a normal sudoku arrangement; gerechte
Polyominoes
this is the earliest known publication of what is now called a sudoku solution. n-omino
Following a suggestion of F. Ragaller, Behrens called these designs “gerechte” Golomb
monominoes
(“equitable”) latin squares or latin rectangles, because they assign neighborhood dominoes
groupings to tracts of land that have been subjected to all n treatments. trominoes
tetrominoes
All of his designs were partitions of rectangles into connected regions, each pentominoes
with n square cells. We’ll see next that that idea actually turns out to have its hexominoes
polyominoes
own distinguished history of fascinating combinatorial patterns and recreations. straight
bent
Polyominoes. A rookwise-connected region of n square cells is often called an Tetris
DUDENEY
n-omino, following a suggestion by S. W. Golomb [AMM 61 (1954), 675-682]. trademark
When n = 1, 2, 3, . . . , Golomb’s definition gives us monominoes, dominoes, GOLOMB
Knuth
trominoes, tetrominoes, pentominoes, hexominoes, and so on. In general, when
n is unspecified, Golomb called such regions polyominoes.
We’ve already encountered small polyominoes, together with their relation
to exact covering, in 7.1.4-(i3o). It’s clear that a domino has only one possible
shape. But there are two distinct species of trominoes, one of which is “straight”
(1 x 3) and the other is “bent,” occupying three cells of a 2 x 2 square. Similarly,
the tetrominoes can be classified into five distinct types. (Can you draw all five,
before looking at exercise 274? Tetris’® players will have no trouble doing this.)
The most piquant polyominoes, however, are almost certainly the pentom-
inoes, of which there are twelve. These twelve shapes have become the personal
friends of millions of people, because they can be put together in so many
elegant ways. Sets of pentominoes, made from finely crafted hardwoods or from
brilliantly colored plastic, are readily available at reasonable cost. Every home
really ought to have at least one such set — even though “virtual” pentominoes
can easily be manipulated in computer apps — because there’s no substitute for
the strangely fascinating tactile experience of arranging these delightful physical
objects by hand. Furthermore, we’ll see that pentominoes have much to teach
us about combinatorial computing.
Which English nouns ending in -o pluralize with -s and which with -es?
If the word is still felt as somewhat alien, it takes -s,
while if it has been fully naturalized into English, it takes -es.
Thus, echoes, potatoes, tomatoes, dingoes, embargoes, etc.,
whereas Italian musical terms are altos, bassos, cantos, pianos, solos, etc.,
and there are Spanish words like tangos, armadillos, etc.
I once held a trademark on ‘Pentomino(-es)’, but I now prefer
to let these words be my contribution to the language as public domain.
— SOLOMON W. GOLOMB, letter to Donald Knuth (16 February 1994)
July 26, 2019
16 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
One of the first things we might try to do with twelve pieces of 5 cells each Golomb
Hansson
is to pack them into a rectangular box, either 6 x 10 or 5 x 12 or 4 x 15 or Golomb
3 x 20. The first three tasks are fairly easy; but a 3 x 20 box presents more of a Conway
pentominoes, names of
challenge. Golomb posed this question in his article of 1954, without providing L-pentomino, see Q-pentomino
any answer. At that time he was unaware that Frans Hansson had already given F-pentomino, see R-pentomino
N-pentomino, see S-pentomino
a solution many years earlier, in an obscure publication called The Problemist: packing
Fairy Chess Supplement 2, 12 and 13 (June and August, 1935), problem 1844: hexadecimal notation, extended
(36)
Hansson had in fact observed that the bracketed pieces “may also be rotated
through two right angles, to give the only other possible solution.”
This problem, and many others of a similar kind, can be formulated nicely in
terms of exact covering. But before we do this, we need names for the individual
pentomino shapes. Everybody agrees that seven of the pentominoes should be
named after seven consecutive letters of the alphabet:
TU V WXY Z
But two different systems of nomenclature have been proposed for the other five:
F I LP O
P-I^
P Q R S
(S. W. Golomb) (J. H. Conway)
where Golomb liked to think of the word ‘Filipino’ while Conway preferred to
map the twelve pentominoes onto twelve consecutive letters. Conway’s scheme
tends to work better in computer programs, so we’ll use it here.
The task of 3 x 20 pentomino packing is to arrange pentominoes in such a
way that every piece name {O, P, . . . , Z} is covered exactly once, and so is every
cell ij for 0 < i < 3 and 0 < j < 20. Thus there are 12 + 3 • 20 = 72 items; and
there’s an option for each way to place an individual pentomino, namely
‘ O 00 01 02 03 04’
‘O 2f 2g 2h 2i 2j’
(37)
‘P 00 01 02 10 11’
‘ Z 0j 1h 1i 1j 2h’
if we extend hexadecimal notation so that the “digits” (a, b, . . . , j) represent
(10, 11, . . . , 19). In this list, pieces (O, P, . . . , Z) contribute respectively (48, 220,
July 26, 2019
7.2.2.1 DANCING LINKS: POLYOMINOES 17
136, 144, 136, 72, 110, 72, 72, 18, 136, 72) options, making 1236 altogether. Hansson
symmetry removal
Exercise 266 explains how to generate all of the options for problems like this. V pentomino
When Algorithm X is applied to (37), it finds eight solutions, because each remove the symmetry
flipped over
of Hansson’s arrangements is obtained with horizontal and/or vertical reflection. secondary
We can remove that symmetry by insisting that the V pentomino must appear benchmarks
history
in its ‘Г-like’ orientation, as it does in (36), namely by removing all but 18 of its
72 options. (Do you see why? Think about it.) Without that simplification, an
32,644-node search tree finds 8 solutions in 146 megamems; with it, a 21,805-node
search tree finds 2 solutions in 103 megamems.
A closer look shows that we can actually do much better. For example, one
of the Г-like options for V is ‘ V 09 0a 0b 19 29’, representing
(38)
but this placement could never be used, because it asks us to pack pentominoes
into the 27 cells at V’s left. Many of the options for other pieces are similarly
unusable, because (like (38)) they isolate a region whose area isn’t a multiple of 5.
In fact, if we remove all such options, only 728 of the original 1236 potential
placements remain; they include respectively (48, 156, 132, 28, 128, 16, 44, 16,
12, 4, 128, 16) placements of (O, P, . . . , Z). That gives us 716 options, when
we remove also the 12 surviving placements for V that make it non-'Г’. When
Algorithm X is applied to this reduced set, the search tree for finding all solutions
goes down to 1243 nodes, and the running time is only 4.5 megamems.
(There’s also a slightly better way to remove the symmetry: Instead of
insisting that piece V looks like ‘Г’ we can insist that piece X lies in the left half,
and that piece Z hasn’t been “flipped over.” This implies that there are (16, 2,
8) potential placements for (V, X, Z), instead of (4, 4, 16). The resulting search
tree has just 1128 nodes, and the running time is 4.0 Mp.)
Notice that we could have begun with a weaker formulation of this problem:
We could merely have asked for pentomino arrangements that use each piece at
most once, while covering each cell ij exactly once. That would be essentially the
same as saying that the piece names {O, P, . . . , Z} are secondary items instead of
primary. Then the original set of 1236 options in (37) would have led to a search
tree with 61,851 nodes, and a runtime of 291 Mp. Dually, we could have kept
the piece names primary but made the cell names secondary; that would have
yielded a 1,086,521,921-node tree, with a runtime of 2.94 Tp! These statistics
are curiously reversed, however, with respect to the reduced set of 716 options
obtained by discarding cases like (38): Then piece names secondary yields 19306
nodes (68 Mp); cell names secondary yields 11656 nodes (37 Mp).
In the early days of computing, pentomino problems served as useful bench
marks for combinatorial calculations. Programmers didn’t have the luxury of
large random-access memory until much later; therefore techniques such as
dancing links, in which more than a thousand options are explicitly listed and
manipulated, were unthinkable at the time. Instead, the options for each piece
were implicitly generated on-the-fly as needed, and there was no incentive to use
July 26, 2019
18 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
fancy heuristics while backtracking. Each branch of the search was essentially MRV heuristic
focus
based on the available ways to cover the first cell ij that hadn’t yet been occupied. assembly language
We can simulate the behavior of those historic methods by running Algo macro instructions
Fletcher
rithm X without the MRV heuristic and simply setting i ^ RLINK(0) in step X3. de Bruijn
An interesting phenomenon now arises: If the cells ij are considered in their MRV heuristic
Polycubes
natural order — first 00, then 01, . . . , then 0j, then 10, . . . , finally 2j —the monocubes
search tree has 1.5 billion nodes. (There are 29 ways to cover 00; if we choose dicubes
tricubes
‘00 01 02 03 04 O’ there are 49 ways to cover 05; and so on.) But if we consider tetracubes
the 20 x 3 problem instead of 3 x 20, so that the cells ij for 0 < i < 20 and pentacubes
0 < j < 3 are processed in order 00, 01, 02, 10, ..., 2j, the search tree has just n-cubes
cubie: A 1 x 1 x 1 cube inside a larger bo
71191 nodes, and all eight solutions are found very quickly. (This speedup is tetromino
mostly due to having a better “focus,” which we’ll discuss later.) Again we see flip it over
chiral
that a small change in problem setup can have enormous ramifications. Kelvin
The best of these early programs were highly tuned, written in assembly lan cuboids
parallelepipeds
guage with ingenious uses of macro instructions. Memwise, they were therefore bricks
superior to Algorithm X on smallish problems. [See J. G. Fletcher, CACM 8, 10 Hein
bent tromino
(October 1965), cover and 621-623; N. G. de Bruijn, FGbook pages 465-466.] ell tetromino
But the MRV heuristic eventually wins, as problems get larger. tee tetromino
skew tetromino
Exercises 268-323 discuss some of the many intriguing and instructive prob twist tetracube
lems that arise when we explore the patterns that can be made with pentominoes claw tetracube
Soma
and similar families of planar shapes. Several of these problems are indeed
large — beyond the capabilities of today’s machines.
Polycubes. And if you think two-dimensional shapes are fun, you’ll probably
enjoy three dimensions even more! A polycube is a solid object formed by taking
one or more 1 x 1 x 1 cubes and joining them face-to-face. We call them mono
cubes, dicubes, tricubes, tetracubes, pentacubes, etc.; but we don’t call them
“n-cubes” when they’re made from n unit cubies, because mathematicians have
reserved that term for n-dimensional objects.
A new situation arises when n = 4. In two dimensions we found it natural to
regard the tetromino ‘ P—’ as identical to its mirror image ‘—P ’, because we could
simply flip it over. But the tetracube ^j’ is noticeably different from its mirror
reflection ‘g^’, because we can’t change one into the other without going into
the fourth dimension. Polycubes that differ from their mirror images are called
chiral, a word coined by Lord Kelvin in 1893 when he studied chiral molecules.
The simplest polycubes are cuboids — also called “rectangular parallele
pipeds” by people who like long names — which are like bricks of size l x m x n.
But things get particularly interesting when we consider noncuboidal shapes.
Piet Hein noticed in 1933 that the seven smallest shapes of that kind, namely
60 djb, (39)
Martin Gardner wrote about the joys of Soma in Scientific American 199, 3 Gardner
Parker Brothers
(September 1958), 182-188, and it soon became wildly popular: More than two HEIN
million SOMA1® cubes were sold in America alone, after Parker Brothers began Patent
canonical
to market a well-made set together with an instruction booklet written by Hein. factoring
The task of packing these seven pieces into a cube is easy to formulate as an
exact cover problem, just as we did when packing pentominoes. But this time we
have 24 3D-rotations of the pieces to consider, instead of 8 2D-rotations and/or
3D-reflections; so exercise 324 is used instead of exercise 266 to generate the
options of the problem. It turns out that there are 688 options, involving 34 items
that we can call 1, 2, . . . , 7, 000, 001, . . . , 222. For example, the first option
characterizes one of the 144 potential ways to place the “bent” piece 1.
Algorithm X needs just 407 megamems to find all 11,520 solutions to this
problem. Furthermore, we can save most of that time by taking advantage of
symmetry: Every solution can be rotated into a unique “canonical” solution
in which the “ell” piece 2 has not been rotated; hence we can restrict that
piece to only six placements, namely (000, 010, 020, 100), (001, 011, 021, 101),
. . . , (102, 112, 122, 202) —all shifts of each other. This restriction removes 138 =
23 • 144 options, and the algorithm now finds the 480 canonical solutions in just
20 megamems. (These canonical solutions form 240 mirror-image pairs.)
Factoring an exact cover problem. In fact, we can simplify the Soma cube
problem much further, so that all of its solutions can actually be found by hand
in a reasonable time, by factoring the problem in a clever way.
Let’s observe first that any solution to an exact cover problem automatically
solves infinitely many other problems. Going back to our original formulation
in terms of an m x n matrix A = (aij), the task is to find all sets of rows whose
sum is 1 in every column, namely to find all binary vectors x1 .. .xm such that
52”=1 xiaij = 1 for 1 < j < n. Therefore if we set bi = a1ai1 + • • • + anain for
1 < i < m, where (a1,..., an) is any n-tuple of coefficients, the vectors x1 ... xm
will also satisfy im=1 xibi = a1 + • • • + an . By choosing the a’s intelligently we
may be able to learn a lot about the possibilities for x1 . . . xm .
For example, consider again the 6 x 7 matrix A in (5), and let a1 = • • • =
a7 = 1. The sum of the entries in each row of A is either 2 or 3; thus we’re
supposed to cover 7 things, by burying either 2 or 3 at a time. Without knowing
anything more about the detailed structure of A, we can conclude immediately
that there’s only one way to obtain a total of 7, namely by selecting 2 + 2 + 3!
Furthermore, only rows 1 and 5 have 2 as their sum; we must choose them.
July 26, 2019
20 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
Now here’s a more interesting challenge: “Cover the 64 cells of a chessboard chessboard
straight trominoes
with 21 straight trominoes and one monomino.” This problem corresponds to a monomino
big matrix that has 96 + 64 rows and 1 + 64 columns, Golomb
coloring arguments
M 00010203040506071011 1213141516172021222324 74 75 76 77 Slothouber
0 1 1 1 000000000000 00 00 00. .0000 Graatsma
square tetracubes
0 1 0000000 1 000000 0 1 00 00. .0000
0011100000000000000000 . . 0 0 0 0
00 1 0 00 0 00 0 1 00 00 00 0 1 00 0. .0000
00 00 00 0 00 00 00 00 00 00 00 0. .0111 (41)
1 1 00 00 0 00 00 00 00 00 00 00 0. .0000
1 0 1 0 00 0 00 00 00 00 00 00 00 0. .0000
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... 0 0 0 1
where the first 96 rows specify all possible ways to place a tromino and the other
64 rows specify the possibilities for the monomino. Column ij represents cell
(i, j); column ‘M’ means “monomino.”
The three cells (i, j ) covered by a straight tromino always lead to distinct
values of (i - j) mod 3. Therefore, if we add up the 22 columns of (41) for which
(i - j ) mod 3 = 0, we get 1 in each of the first 96 rows, and 0 or 1 in the other
64 rows. We’re supposed to get a total of 22 in the chosen rows; hence the
monomino has to go into a cell (i, j) with i = j (modulo 3).
A similar argument, using i + j instead of i - j , shows that the monomino
must also go into a cell with i + j = 1 (modulo 3). Therefore i = j = 2. We’ve
proved that there are only four possibilities for (i, j), namely (2, 2), (2, 5), (5, 2),
(5, 5). [Golomb made this observation in his 1954 paper that introduced poly-
ominoes, after “coloring” the cells of a chessboard with three colors. The general
notion of factoring includes all such coloring arguments as special cases.]
Our proof that (38) is an impossible pentomino placement can also be
regarded as an instance of factorization. The residual problem, if (38) is chosen,
has a total of either 0 or 5 in the first 27 columns of each remaining row of the
associated matrix. Therefore we can’t achieve a total of 27 from those rows.
Consider now a three-dimensional problem [J. Slothouber and W. Graatsma,
Cubics (1970), 108-109]: Can six 1 x 2 x 2 cuboids be packed into a 3 x 3 x 3
box? This is the problem of choosing six rows of the 36 x 27 matrix
000 001 002 010 011 012 020 021 022 100 101 102 110 111 112 120 121 122 200 201 202 210 211 212 220 221 222
The 27 cubies (i, j, k) of a 3 x 3 x 3 cube fall into four classes, depending on Soma cube
checkerboard coloring
how many of its coordinates have the middle value 1:
Piece 1: (0, 1, 1,1), (0, 0, 2, 1), (0, 1, 2, 0),(0, 2, 1, 0), (1, 1, 1, 0), (1, 2, 0, 0).
Piece 2: (0, 1, 2,1), (0, 2, 2, 0), (1, 2, 1, 0), (2, 2, 0, 0).
Piece 3: (0, 0, 3,1), (0, 2, 1, 1), (0, 3, 1, 0), (2, 1, 1, 0).
Piece 4: (0,1, 2,1), (1, 2,1, 0). (45)
Piece 5: (0, 1, 2,1), (0, 2, 2, 0), (1, 1, 1, 1), (1, 2, 1, 0).
Piece 6: (0, 1, 2,1), (0, 2, 2, 0), (1, 1, 1, 1), (1, 2, 1, 0).
Piece 7: (0, 2, 1,1), (0, 3, 0, 1), (1, 1, 2, 0), (1, 3, 0, 0).
(This is actually much more information than we need, but it doesn’t hurt.)
Looking only at the totals for v, we see that we must have
(0 or 1) + (0, 1, or 2) + (0 or 2) + (0 or 1) + (0 or 1) + (0 or 1) + (0 or 1) = 8;
(0 or 1) + (1 or 2) + 2 + (0 or 1) + (0 or 1) + (0 or 1) + (0 or 1) = 8,
thus eliminating several options for pieces 2 and 3. More precisely, piece 2 must
touch at least one vertex; piece 3 must be placed along an edge.
Looking next at the totals for v + f , which are the “black” cubies if we color
them alternately black and white with black in the corners, we must also have
(1 or 2)+2+3+2+2+2+ (1 or 3) = 14;
July 26, 2019
22 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
and the only way to achieve this is with two from piece 1 and one from piece 7: Guy, Michael
Guy
Piece 1 must occupy two black cubies, and piece 7 must occupy just one.
Conway
We have therefore eliminated 200 of the 688 options in the list that begins Berlekamp
Conway
with (40). And we also know that exactly five of the pieces 1, 2, 4, 5, 6, 7 occupy Guy
as many of the corner vertices as they individually can. This extra information symmetry
can be encoded by introducing 13 new primary items
*, 1+, 1-, 2+, 2-, 4+, 4-, 5+, 5-, 6+, 6-, 7+, 7- (46)
and six new options
* 1+ 2- 4 5- 6- 7
* 1- 2+ 4 5- 6- 7
* 1- 2- 4+ 5- 6- 7
(47)
* 1- 2- 4 5+ 6- 7
* 1- 2- 4 5- 6+ 7
* 1- 2- 4- 5- 6- 7+
and by appending p+ or p- to each of piece p’s options that do or don’t touch
the most corners. For example, this new set of 6 + 488 options for the Soma
cube problem includes the following typical ways to place various pieces:
‘1 000 001 011 1+’
‘1 001 011 101 1-’
‘2 000 001 002 010 2+
‘2 000 001 011 021 2-
‘3 000 001 002 011’
‘4 000 001 011 012 4+
‘4 000 011 111 121 4-
‘5 000 001 010 110 5+
‘5 001 010 011 101 5-
‘6 000 001 010 101 6+
‘6 001 010 011 110 6-
‘7 000 001 010 100 7+
‘7 001 010 011 111 7-
As before, Algorithm X finds 11,520 solutions; but now it needs only 108
megamems to do so. Each of the new options is used in at least 21 of the solutions,
hence we’ve removed all of the “fat” in the original set. [This instructive analysis
of Soma is due to M. J. T. Guy, R. K. Guy, and J. H. Conway in 1961. See
Berlekamp, Conway, and Guy, Winning Ways, second edition (2004), 845-847.]
To reduce the number of solutions, using symmetry, we can force piece 3
to occupy the cells {000, 001, 002, 011} (thus saving a factor of 24), and we
can remove all options for piece 7 that use a cell ijk with k = 2 (saving an
additional factor of 2). From the remaining 455 options, Algorithm X needs just
2 megamems to generate all 240 of the essentially distinct solutions.
The seven Soma pieces are amazingly versatile, and so are the other poly
cubes of small sizes. Exercises 325-345 explore some of their remarkable prop
erties, together with historical references.
July 26, 2019
7.2.2.1 DANCING LINKS: COLOR-CONTROLLED COVERING 23
Color-controlled covering. Take a break! Before reading any further, please color-controlled—
word search
spend a minute or two solving the “word search” puzzle in Fig. 71. Compar hidden mathematicians+
atively mindless puzzles like this one provide a low-stress way to sharpen your mathematicians+
color codes
word-recognition skills. It can be solved easily — for instance, by making eight
passes over the array — and the solution appears in Fig. 72 on the next page.
Our goal in this section is not to discuss how to solve such puzzles; instead, we
shall consider how to create them. It’s by no means easy to pack those 27 names
into the box in such a way that their 184 characters occupy only 135 cells, with
eight directions well mixed. How can that be done with reasonable efficiency?
For this purpose we shall extend the idea of exact covering by introducing
color codes. Let’s imagine that each cell ij of the array is to be “colored” with
one of the letters {A, . . . , Z}. Then the task of creating such a puzzle is essentially
to choose from among a vast set of options
‘ABEL 00:A 01:B 02:E 03:L’
‘ABEL 00:A 10:B 20:E 30:L’
‘ABEL 00:A 11:B 22:E 33:L’
‘ABEL 00:L 01:E 02:B 03:A’
(48)
* The journal Acta Mathematica celebrated its 21st birthday by publishing a special Table
Generale des Tomes 1—35, edited by Marcel Riesz (Uppsala: 1913), 179 pp. It contained a
complete list of all papers published so far in that journal, together with portraits and brief
biographies of all the authors. The 27 mathematicians mentioned in Fig. 71 are those who
were subsequently mentioned in Volumes 1, 2, or 3 of The Art of Computer Programming —
except for people like MITTAG-LEFFLER or POINCARE, whose names contain special characters.
There also are informal constraints: It’s desirable to have many shared letters
between names, and to intermix the various directions, so that the puzzle has
plenty of variety and perhaps a few surprises. But conditions (i) and (ii) are
the important criteria for a computer to consider; the auxiliary informalities are
best handled interactively, with human guidance.
Notice that the color constraints (ii) are significantly different from the name
constraints (i). Several distinct options are allowed to specify the color of the
same cell, as long as those specifications don’t conflict with each other.
Let us therefore define a new problem, exact covering with colors, or XCC for
short. As before, we’re given a set of items, of which N1 are primary and N - N1
are secondary. We’re also given a family of M options, each of which includes at
least one primary item. The new rule is that a color is assigned to the secondary
items of each option. The new task is to find all choices of options such that
i) every primary item occurs exactly once; and
ii) every secondary item has been assigned at most one color.
The primary items are required; the secondary items are elective.
Color assignments are denoted by a colon; for example, ‘ 00: A’ in (48) means
that color A is assigned to the secondary item 00. When a secondary item of an
option is not followed by a colon, it is implicitly assigned a unique color, which
doesn’t match the color of any other option. Therefore the ordinary exact cover
problems that we’ve been studying so far, in which secondary items don’t explic
itly receive colors but cannot be chosen in more than one option, are just special
cases of the XCC problem, even though nothing about color was mentioned.
A tremendous variety of combinatorial problems can be expressed readily in
the XCC framework. And there’s good news: The dancing links technique works
beautifully with such problems! Indeed, we will see that this considerably more
general problem can be solved with only a few small extensions to Algorithm X.
The nodes of Algorithm X have just three fields: TOP, ULINK, and DLINK.
We now add a fourth field, COLOR; this field is set to the positive value c when
July 26, 2019
7.2.2.1 DANCING LINKS: COLOR-CONTROLLED COVERING 25
the node represents an item that has explicitly been assigned color c. Consider,
for example, the following toy problem with three primary items {p, q, r} and
two secondary items {x, y}, where the options are
‘p q x y:A’ ;
‘p r x:A y’ ;
‘p x:B’ ; (49)
‘q x:A’ ;
‘r y:B’ .
Table 2 shows how it would be represented in memory, extending the conventions
of Table 1. Notice that COLOR = 0 when no color has been specified. The COLOR
fields of the header nodes (nodes 1-5 in this example) need not be initialized
because they’re never examined. The COLOR fields of the spacer nodes (nodes 6,
11, 16, 19, 22, 25) are unimportant, except that they must be nonnegative.
Table 2
THE INITIAL CONTENTS OF MEMORY CORRESPONDING TO (49)
i: 0 1 2 3 4 5 6
NAME(i): — p q r x y —
LLINK(i): 3 0 1 2 6 4 5
RLINK(i): 1 2 3 0 5 6 4
x: 0 1 2 3 4 5 6
LEN(x): — 3 2 2 4 3 0
ULINK(x): — 17 20 23 21 24 —
DLINK(x): — 7 8 13 9 10 10
x: 7 8 9 10 11 12 13
TOP(x): 1 2 4 5 -1 1 3
ULINK(x): 1 2 4 5 7 7 3
DLINK(x): 12 20 14 15 15 17 23
COLOR(x): 0 0 0 A 0 0 0
x: 14 15 16 17 18 19 20
TOP(x): 4 5 -2 1 4 -3 2
ULINK(x): 9 10 12 12 14 17 8
DLINK(x): 18 24 18 1 21 21 2
COLOR(x): A 0 0 0 B 0 0
x: 21 22 23 24 25
TOP(x): 4 -4 3 5 -5
ULINK(x): 18 20 13 15 23
DLINK(x): 4 24 3 5 —
COLOR(x): A 0 0 B 0
It’s easy to see how these COLOR fields can be used to get the desired effect:
When an option is chosen, we “purify” any secondary items that it names, by
effectively removing all options that have conflicting colors. One slightly subtle
point arises, because we don’t want to waste time purifying a list that has already
been culled. The trick is to set COLOR(x) <----- 1 in every node x that’s already
known to have the correct color, except in nodes that have already been hidden.
Thus we want to upgrade the original operations cover(i) and hide(p) in (12)
and (13), as well as their counterparts uncover(i) and unhide(p) in (14) and (15),
July 26, 2019
26 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
unhide'(p) is like unhide(p), but it ignores node q when COLOR(q) < 0. (53)
Our colorful algorithm also introduces two new operations and their inverses:
f If COLOR(p) = 0, cover'(j);
commit(p, j) = if COLOR(p) > 0, purify(p). (54)
..
{While q = i, do the following and set q ^ DLINK(q):
if COLOR(q) = c, set COLOR(q) ^ -1;
otherwise hide'(q).
I If COLOR(p) = 0, uncover'(j);
uncommit(p, j) = if COLOR(p) > 0, unpurify(p).
,
(55)
(56)
>
{
While q = i, do the following and set q ^ ULINK(q): , .
if COLOR(q) < 0, set COLOR(q) ^ c; (57)
otherwise unhide'(q).
Otherwise Algorithm C is almost word-for-word identical to Algorithm X.
Algorithm C (Exact covering with colors). This algorithm visits all solutions
to a given XCC problem, using the same conventions as Algorithm X.
C1. [Initialize.] Set the problem up in memory, as in Table 2. (See exercise 8.)
Also set N to the number of items, Z to the last spacer address, and l ^ 0.
C2. [Enter level l.] If RLINK(0) = 0 (hence all items have been covered), visit the
solution that is specified by x0x1 . . . xl-1 and go to C8. (See exercise 13.)
C3. [Choose i.] At this point the items i1, . . . , it still need to be covered, where
i1 = RLINK(0), ij+1 = RLINK(ij), RLINK(it) = 0. Choose one of them, and
call it i. (The MRV heuristic of exercise 9 often works well in practice.)
C4. [Cover i.] Cover item i using (50), and set xl ^ DLINK(i).
C5. [Try xl .] If xl = i, go to C7 (we’ve tried all options for i). Otherwise set
p ^ xl + 1, and do the following while p = xl: Set j ^ TOP(p); if j < 0, set
p ^ ULINK(p); otherwise commit(p, j) and set p ^ p +1. (This covers the
items = i in the option that contains xl.) Set l ^ l +1 and return to C2.
C6. [Try again.] Set p ^ xl — 1, and do the following while p = xl: Set j ^
TOP(p); if j < 0, set p ^ DLINK(p); otherwise uncommit(p, j) and set
p ^ p — 1. (This uncovers the items = i in the option that contains xl, using
the reverse order.) Set i ^ TOP(xl), xl ^ DLINK(xl), and return to C5.
C7. [Backtrack.] Uncover item i using (52).
C8. [Leave level l.] Terminate if l = 0. Otherwise set l ^ l — 1 and go to C6. |
July 26, 2019
7.2.2.1 dancing links: color-controlled covering 27
Algorithm C applies directly to several problems that we’ve already dis word rectangles
de Bruijn cycles
cussed in previous sections. For example, it readily generates word rectangles, tetrad tiles
as well as intriguing patterns of words that have more intricate structure (see MacMahon
Patent
exercises 87-93). We can use it to find all de Bruijn cycles, and their two Jocelyn
dimensional counterparts (see exercises 94-97). The extra generality of exact superdominoes
chiral pairs
covering options also invites us to impose additional constraints for special MACMAHON
applications. Furthermore, Algorithm C facilitates experiments with the tetrad rotation
reflection
tiles that we studied in Section 2.3.4.3 (see exercises 120 and 121). dihedral group
The great combinatorialist P. A. MacMahon introduced several families of color symmetries
colored cubes
colorful geometric patterns that continued to fascinate him throughout his life.
For example, in U.K. Patent 3927 of 1892, written with J. R. J. Jocelyn, he con
sidered the 24 different triangles that can be made with four colors on their edges,
(58)
and showed two ways in which they could be arranged to form a hexagon with
matching colors at adjacent edges and with solid colors on the outer boundary:
(b) (59)
(Notice that chiral pairs, like and in (58), are considered to be distinct;
MacMahon’s tiles can be rotated, but they can’t be “flipped over.”)
Introducing multiplicity. We’ve now seen from numerous examples that XCC
constraint satisfaction problem
Algorithm C — which extends Algorithm X and solves arbitrary XCC problems — CSP
is enormously versatile. In fact, there’s a sense in which every constraint satis Wainwright
partridge puzzle
faction problem is a special case of an XCC problem (see exercise 100). 3
cubes, numbers of the form n
But we can extend Algorithm C even further, again without substantial squares, numbers of the form n
2
changes, so that it goes well beyond the original notion of exact covering. For Christmas
example, let’s consider Robert Wainwright’s “partridge puzzle” (1981), which
was inspired by the well-known fact that the sum of the first n cubes is a perfect
square:
13 + 23 + ••• + n3 = N2, where N =1 + 2+ ••• + n. (6o)
Wainwright wondered if this relation could be verified geometrically, by taking
one square of size 1 x 1, two squares of size 2 x 2, ..., n squares of size n x n, and
packing them all into a big square of size N x N. (We know from exercise 1.2.1-8
that 4k squares of each size k x k can be packed into a 2N x 2N square. But
Wainwright hoped for a more direct corroboration of (6o).) He proved the task
impossible for 2 < n < 5, but found a perfect packing when n = 12; so he thought
of the 12 days of Christmas, and named his puzzle accordingly (see exercise 154).
This partridge puzzle is easily expressed in terms of options that involve n
items #k for 1 < k < n, as well as N2 items ij for 0 < i, j < N . By analogy
with what we did with pentominoes in (37), the options are
6 6 6 6
8 8 8 8 8 8
6 6 5
4 4 7
5 6 5
8 8 8
2 I 2
3 3 5 1
5 5 1 4 4
3
8
7
7 6 4
7
4
(62)
8 8 7 6
6 7 8 8
6 7
5 5 5 7
8
2 3 2
3 8
7 7 7 7 6 7 7
4 4 5
3
When we first defined exact cover problems, near the beginning of this intervals
multiple covering with colors
section, we considered M x N matrices of 0s and 1s, such as (5). In matrix terms, primary item
the task was to find all subsets of the rows whose sum is 11 . . . 1. Algorithm M is secondary items
cover problem
going to do much more: It will find all subsets of rows whose sum is v1 v2 . . . vN , Wainwright
where v1 v2 . . . vN is any desired vector of multiplicities. partridge puzzle
chessboard
In fact, Algorithm M will go further yet, by allowing intervals [uj . . vj] 5-queens problem
to be prescribed for each multiplicity. It will actually solve the general MCC n queens problem
queen domination problem
problem, “multiple covering with colors,” which is defined as follows: There are de Jaenisch
N items, of which N1 are primary and N - N1 are secondary. Each primary
item j for 1 < j < N1 is assigned an interval [uj .. vj] of permissible values,
where 0 < uj < vj and vj > 0. There also are M options, each of which includes
at least one primary item. A color is assigned to the secondary items of each
option; a “blank” color is understood to represent a unique color that appears
nowhere else. The task is to find all subsets of options such that
i) each primary item j occurs at least uj times and at most vj times;
ii) every secondary item has been assigned at most one color.
Thus every XCC problem is the special case uj = vj = 1 of an MCC problem.
Indeed, the MCC problem is extremely general! For example, its special case
uj = 1 and vj = M, without secondary items, is the classical not-necessarily-
exact cover problem, in which we simply require each item to appear in at least
one option. Section 7.2.2.6 will be entirely devoted to the cover problem.
Let’s confine our attention here to a few more examples of the MCC problem,
in preparation for Algorithm M. In the first place, we can tackle a refined version
of Wainwright’s partridge puzzle: “Pack at most k squares of size k x k, for
1 < k < n, into an N x N square, without overlapping, so that as many as
possible of the N2 cells are covered.” (As before, N = 1 + 2+ • • • + n.) We know
from (62) that the entire square can be covered when n = 8; but smaller cases
are another story. Solutions for 2 < n < 5 are readily found by hand:
(63)
And to prove that every packing for n = 5 must leave at least 13 cells vacant,
Algorithm M will show that the MCC problem (61) has no solutions when items
#1, #2, #3 are respectively given the multiplicities [0 . . 13], [0 . . 2], [0 . . 3] instead
of 1, 2, 3. Exercise 157 constructs optimum packings when n = 6 and n = 7,
thereby settling all small cases of the partridge puzzle.
Next, let’s consider an MCC problem of quite a different kind: “Place m
queens so that they control all cells of an n x n chessboard.” (The classic 5-queens
problem — which should be distinguished from the ‘5 queens problem’ considered
earlier — is the special case m = 5, n = 8.) Exercise 7.1.4-241 discusses the his
tory of this problem, which goes back to a remarkable book by de Jaenisch (1863).
July 26, 2019
30 combinatorial searching (f5c: 26 Jul 2019 @ 2051) 7.2.2.1
We can solve it, MCC-wise, by introducing n2 + 1 primary items, namely Secondary items
color controls
the pairs ij for 0 < i, j < n and the special item #, together with n2 options: word rectangles
English
‘# ij iiji 'i2j2 ... itjt for 0 < i, j < n, (64) WORDS(2000)
Stanford GraphBase
where i1j1, i2j2, . . . , itjt are the cells attacked by a queen on ij. Each cell ij is
assigned the multiplicity [1 . . m]; item # gets multiplicity m.
From this specification Algorithm M will readily find all 4860 solutions to
the 5-queens problem, after 13 gigamems of computation. For example, it begins
with 22 ways to cover the corner cell 00. If it puts a queen there, it has 22 ways
to cover cell 17; and so on. The branching factor at each step tends to decrease
rapidly after three queens have been placed.
The beauty of the MCC setup in (64) is that we can solve many related
problems by making simple changes to the specifications. For example, by
retaining only the 36 options for 1 < i, j < 6, we could find the 284 solutions that
place no queens at the edges of the board. Or by removing the 16 options for
2 < i, j < 5, we would discover that exactly 880 of the solutions place no queens
near the middle. Exactly 88 solutions avoid the central two rows and the central
two columns. Exactly 200 solutions put all five queens on “black” cells (with
i + j even). Exactly 90 avoid the upper left and lower right quadrants. Exactly
2 solutions (can you find them?) place all five queens in the top half of the board.
By changing the multiplicities in the bottom row from [1 . . 5] to 1, we get
18 solutions for which every cell in that row is attacked just once. Or, changing
the central 16 multiplicities to [2 . . 5] yields 48 solutions for which every cell near
the center is attacked at least twice. Changing all the cell multiplicities to [1 . . 4]
reduces the number of solutions from 4860 to 3248; changing them all to [1 . . 3]
reduces it to 96. Exercise 161 illustrates several of the less obvious possibilities.
(65)
The examples of MCC problems that we’ve seen so far have involved primary
items only. Secondary items, and their color controls, add new dimensions and
extend the range of applications enormously. Consider, for example, the word
rectangles that we investigated briefly in Section 7.2.2. Here’s a 4 x 5 word
rectangle that uses only nine distinct letters of the alphabet:
LABEL
ABIDE
SLAIN.
TESTS
Can we find one that uses only eight distinct letters, while sticking to common
words? (More precisely, is there such a rectangle whose columns are chosen from
the most common 1000 four-letter words of English, and whose rows belong to
WORDS(2000), the curated collection from the Stanford GraphBase?)
July 26, 2019
7.2.2.1 dancing links: A new dance step 31
The answer is yes, and in fact there are six solutions: nonsharp preference heuristic
recursively
STRUT EASED WADED RADAR LLAMA SCARS
TEASE AGILE ARENA ARENA EAGER COCOA
(66)
EATEN SENSE SEEDS SEATS STEAM ARRAY
PRESS EDGED HARSH HARSH TESTS REEDS
One way to find them is to set up an MCC problem in which the primary
items are A0, A1, A2, A3, D0, D1, D2, D3, D4, #A, #B, . . . , #Z, #; they all
have multiplicity 1 except that # has multiplicity 8. There also are secondary
items A, B, ..., Z, and ij for 0 < i < 4, 0 < j < 5. The letter-counting is handled
by 2 • 26 short options:
‘#A A:0’, ‘#A A:1 #’; ‘#B B:0’, ‘#B B:1 #’; ...; ‘#Z Z:0’, ‘#Z Z:1 #’. (67)
Then each legal 5-letter word c1c2c3c4c5 yields four options, ‘Ai i0:c1 i1:c2 i2:c3
i3:c4 i4:c5 c1:1 c2:1 c3:1 c4:1 c5:1’, for 0 < i < 4; each legal 4-letter word c1c2c3c4
yields five options, ‘Dj 0j:c1 1j :c2 2j:c3 3j :c4 c1:1 c2 :1 c3 :1 c4:1’, for 0 < j < 5.
(Letters that occur more than once in a word are listed only once.)
For example, one of the options chosen for the first solution in (66) is ‘A3
30:P 31:R 32:E 33:S 34:S P:1 R:1 E:1 S:1’; it forces the options ‘#P P:1 #’, ‘#R
R:1 #’, ‘#E E:1 #’, ‘#S S:1 #’ to be chosen too, thus contributing four to the
number of chosen options that contain #.
By the way, when Algorithm M is applied to these options, it’s important to
use the “nonsharp preference heuristic” discussed in exercise 10 and its answer.
Otherwise the algorithm will foolishly make binary branches on the items #A,
. . . , #Z, before trying out actual words. A 1000-way branch on D0 is much
better than a 2-way branch on #Q, in this situation.
of b might have assigned color values that make LEN(q) < 1. (The choice of b tweaking
might also have made c, d, and/or e illegal.) FT[l]
first tweaks
The main point is that, after we’ve chosen the first of three options for p in untweaking
the original problem, we have not “covered” p as we did in Algorithms X and C. link manipulations
Item p remains on an equal footing with all other active items of the reduced
problem, so we need to modify (68) accordingly.
The operation of reducing the problem by removing an option from an item
list, in the presence of multiplicity, is called “tweaking” that option. For example,
just after the algorithm has chosen b as the first option for p, it will have tweaked
both a and b. This operation is deceptively simple:
. hi h _ l'hide'(x) and set d ^ DLINK(x), DLINK(p) ^ d, \
wea (x,p) = |uLiNK(d) ^ p, LEN(p) ^ LEN(p) - 1. ( 9)
(See exercise 163. This computation relies on a surprising fact proved in exercise
2(a), namely that unhiding can safely be done in the same order as hiding.)
The same mechanism can be used when the specified multiplicity is an
interval instead of a single number. For example, suppose item p in the example
above is required to occur in either 2, 3, or 4 options, not exactly 3. Then the
first option chosen must be a, b, c, or d; and the reduced problem will ask p to
occur in either 1, 2, or 3 of the options that remain. Eventually the algorithm
will resort to untweaking, after a, b, c, and d have all been tweaked and explored.
Similarly, if p’s multiplicity has been specified to be either 0, 1, or 2, the
algorithm below will tweak each of a through e in turn. It will also run though all
solutions that omit all of p’s options, before finally untweaking and backtracking.
July 26, 2019
7.2.2.1 DANCING LINKS: A NEW DANCE STEP 33
A special case arises, however, when p’s multiplicity has been specified to be tweak7
either 0 or 1. In such cases we’re not allowed to choose options b, c, d, or e after untweak7
MRV
option a has been chosen. Therefore it’s important to invoke cover'(p), as in LEN
Algorithm C, instead of hiding one option at a time. (See (50).) The individual BOUND
SLACK
options of p are then tweaked, to remove them one by one from the active list; this
tweaking uses the special operation tweak'(x,p), which is like tweak(x,p) in (69)
except that it omits the operation hide'(x), because hiding was already done
when p was covered. Finally, the case of 0-or-1 multiplicity eventually concludes
by invoking the routine untweak'(l), which is like untweak(l) in (71) except that
(i) it omits unhide'(x), and (ii) it calls uncover'(p) after restoring LEN(p).
We’re ready now to write Algorithm M, except that we need a way to rep
resent the multiplicities in the data structures. For this purpose every primary
item has two new fields, SLACK and BOUND. Suppose the desired multiplicity of p
is in the interval [u..v], where 0 < u < v and v = 0; Algorithms X and C
correspond to the case u = v = 1. Then we set
when the algorithm begins. The value of SLACK(p) will never be changed. But
BOUND(p) will decrease dynamically, as we reduce the problem, so that we will
never choose more options for p than its current bound.
Algorithm M (Covering with multiplicities and colors). This algorithm visits
all solutions to a given MCC problem, extending Algorithms X and C.
M1. [Initialize.] Set the problem up in memory as in step C1 of Algorithm C,
with the addition of multiplicity specifications (72). Also set N to the
number of items, N1 to the number of primary items, Z to the last spacer
address, and l ^ 0.
M2. [Enter level l.] If RLINK(0) = 0 (hence all items have been covered), visit the
solution that is specified by x0x1 . . . xl-1 and go to M9. (See exercise 164.)
M3. [Choose i.] At this point the items i1 , . . . , it still need to be covered, where
i1 = RLINK(0), ij+1 = RLINK(ij), RLINK(it) = 0. Choose one of them, and
call it i. (The MRV heuristic of exercise 166 often works well in practice.)
If the branching degree 6i is zero (see exercise 166), go to M9.
M4. [Prepare to branch on i.] Set xl ^ DLINK(i) and BOUND(i) ^ BOUND(i) —1.
If BOUND(i) is now zero, cover item i using (50). If BOUND(i) = 0 or
SLACK(i) = 0, set FT[l] ^ xl.
M5. [Possibly tweak xl .] If BOUND(i) = SLACK(i) = 0, go to M6 if xl = i, to M8
ifxl = i. (That case is like Algorithm C.) Otherwise if LEN(i) < BOUND(i)-
SLACK(i) , go to M8 (list i is too short). Otherwise if xl = i, call tweak(xl , i)
(see (69)), or tweak'(xl, i) if BOUND(i) = 0. Otherwise if BOUND(i) = 0, set
p ^ LLINK(i), q ^ RLINK(i), RLINK(p) ^ q, LLINK(q) ^ p.
M6. [Try xl.] If xl = i, set p ^ xl + 1, and do the following while p = xl: Set j ^
TOP(p); if j < 0, set p ^ ULINK(p); otherwise if j < N1, set BOUND(j) ^
BOUND(j) — 1, p ^ p +1, and cover'(j) if BOUND(j) is now 0; otherwise
July 26, 2019
34 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
commit(p, j) and set p ^ p + 1. (This loop covers or partially covers the Analysis of algorithms—
exact cover problem
items = i in the option that contains xl.) Set l ^ l +1 and return to M2.
0s and 1s
M7. [Try again.] If xl = i, set p ^ xl — 1, and do the following while p = xl: strict
doomsday function
Set j ^ TOP(p); if j < 0, set p ^ DLINK(p); otherwise if j < N1, set recursively
BOUND(j) ^ BOUND(j) + 1, p ^ p — 1, and uncover'(j) if BOUND(j) is
now 1; otherwise uncommit(p, j) and set p ^ p — 1. (This loop uncovers
the items = i in the option that contains xl , using the reverse order.) Set
xl ^ DLINK(xl) and return to M5.
M8. [Restore i.] If BOUND(i) = SLACK(i) = 0, uncover item i using (52).
Otherwise call untweak(l) (see (71)), or untweak'(l) if BOUND(i) = 0. Set
BOUND(i) ^ BOUND(i) + 1.
M9. [Leave level l.] Terminate if l = 0. Otherwise set l ^ l — 1. If xl < N, set
i ^ xl, p ^ LLINK(i), q ^ RLINK(i), RLINK(p) ^ LLINK(q) ^ i, and go
to M8. Otherwise set i ^ TOP(xl) and go to M7. |
*Analysis of Algorithm X. Now let’s get quantitative, and see what we can
actually prove about the running time of these algorithms.
For simplicity, we’ll ignore color constraints and look only at Algorithm X,
as it finds all solutions to an exact cover problem, where the problem is specified
in terms of an M x N matrix A of 0s and 1s such as (5).
We’ll assume that the problem is strict, in the sense that no two rows of
the matrix are identical, and no two columns of the matrix are identical. For if
two or more rows or columns are equal, we need keep only one of them; it’s easy
to relate all solutions of the original problem A to the solutions of this reduced
problem A'. (See exercise 179.)
Our first goal will be to find an upper bound on the number of nodes in the
search tree, as a function of the number of rows of A (the number of options).
This upper bound grows exponentially, because the exact cover problem can have
lots of solutions; but we’ll see that it can’t actually be extremely large.
For this purpose we’ll define the doomsday function D(n), which will have the
property that the search tree for every strict exact cover problem with n options
has at most D(n) nodes, when Algorithm X uses the MRV heuristic in step X3.
The search tree has a root node labeled with the original matrix A, and its
other nodes are defined recursively: When a node at level l is labeled with a
subproblem for which step X3 makes a t-way branch, that node has t subtrees,
whose roots are labeled by the reduced problem that remains after step X4 has
covered item i and after step X5 has optionally covered one or more other items j ,
for t different choices of xl .
Here, for example, is the complete search tree when A is the matrix of (5):
(Each matrix and submatrix in this diagram has been framed with a light-gray strict
MRV
border. The node at bottom left illustrates a 0x 1 submatrix, where the algorithm doomsday function
had to backtrack because it had no way to cover the remaining column. The
node at bottom right illustrates a 0x0 submatrix, which happens to be a solution
to the 1 x 2 problem above it.) We can, if we like, reduce all of the submatrices
by eliminating repeated columns, although Algorithm X doesn’t do this; then
we get strict exact cover problems at every node of the search tree:
(73)
A t-way branch implies that the matrix A has a certain structure. We know
that there’s some column, say i1 = i, that has 1 in exactly t rows, say o1, . . . , ot,
and that every column contains at least t 1s. When we branch on row op, for 1 <
p < t, the reduced problem that defines the pth subtree will retain all but sp of
the rows of A, where sp is the number of rows that intersect op. We can order the
rows so that s1 < • • • < st. For example, in (73) we have t = 2 and s1 = s2 = 4.
A nice thing now happens: There’s always a unique index 0 < t' < t such that
D(n) = max{d(n, t, t') | 1 < t < n and 0 < t' < t}, (77)
where d(n, t, t') is an upper bound for the size of the search tree over all n-option Eppstein
author
strict exact cover problems whose parameters (74) are t and t'. One such bound, birthday
handles the case t' = 0, because the search tree in that case is a t-way branch
(79)
d(n,t,t') = t' +t' • D(n — t —t'+1) + (t — t') • D(n —t —t'— 1), if 1 < t' < t. (80)
It can be justified by the structure theory of exercise 180, using the fact that
each of the first t' — 1 branches is immediately followed by a 1-way branch. For
example, the search tree looks like this when t = 5 and t' = 3:
(81)
Here A'1 is the only way to cover i2 in A1, and A2 is the only way to cover i3 in
A2. The strict problems A'1, A2, and A3 have at most n — 7 options; A4 and A5
have at most n — 9. Therefore (81) has at most 3 + 3D(n — 7) + 2D(n — 9) nodes.
With an easy computer program, (76), (78), and (80) lead to the values
n =0 1 2 345 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
D(n) = 1 1 2 4 5 6 10 13 17 22 31 41 53 69 94 125 165 213 283 377 501 661
and it turns out that the maximum is attained uniquely when t = 4 and t' = 0,
for all n > 19. Hence we have D(n) = 1 + 4D(n — 5) for all sufficiently large n;
and in fact exercise 181 exhibits a simple formula that expresses D(n) exactly.
Theorem E. The search tree of a strict exact cover problem with n options has
O(4n/5) = O(1.31951n) nodes; it might have as many as Q(7n/8) = Q(1.27537n).
Proof. The upper bound follows from exercise 181; the lower bound follows from
the family of problems in exercise 182.
[David Eppstein presented this theorem to the author as a birthday greeting(!);
see 11011110.github.io/blog/2008/01/10/analyzing-algorithm-x.html .]
July 26, 2019
7.2.2.1 DANCING LINKS: ANALYSIS OF ALGORITHM X 37
So far we’ve simply been analyzing the number of nodes in Algorithm X’s updates
set partitions
search tree. But some nodes might cost much more than others, because they
might remove unusually many options from the currently active lists. recursively
Bell numbers
Therefore let’s probe deeper, by studying the number of updates that Algo Gould numbers
rithm X makes to its data structures, namely the number of times that it uses last block of a set partition
tail of a set partition
operation (i) to remove an element from a doubly linked list. (This is also the
number of times that it will eventually use operation (2) to restore an element.)
More precisely, the number of updates is the number of times cover(i) is called,
plus the number of times that hide(p) sets LEN(x) ^ LEN(x) — 1. (See (12)
and (13).) The total running time of Algorithm X, measured in mems, usually
turns out to be roughly 13 times the total number of updates that it makes.
It’s instructive to analyze the number of updates that are made when solving
the “extreme” exact cover problems, which arise when there are n items and
2n — 1 options: Such problems have the most solutions and the most data,
because every nonempty subset of the items is an option. The solutions to
these extreme problems are precisely the set partitions —the ~„ possible ways
to partition the items into disjoint blocks, which we studied in Section 7.2.1.5.
For example, when n = 3 the options are ‘1’, ‘2’, ‘1 2’, ‘3’, ‘1 3’, ‘2 3’, ‘1 2 3’,
and there are '3 = 5 solutions: ‘1’, ‘2’, ‘3’; ‘1’, ‘2 3’; ‘1 2’, ‘3’; ‘1 3’, ‘2’; ‘1 2 3’.
Any given item can be covered in 2n-1 ways; and if we cover it with an
option of size k, we’re left with the extreme problem on the remaining n — k
items. Algorithm X therefore advances 2n-1 times from level 0 to level 1, after
which it essentially calls itself recursively. And at level 0 it performs a certain
number of updates, say vn , regardless of what strategy is used in step X3 to
choose an item for branching. Therefore it makes a total of xn updates, where
n-01 + n--1
n 1
xn = vn + xn-1 +n 1 xn-2 + ••• x0 . (82)
0 0 0 0 0 0 ...
/1 00 0 0 0 0 ...
-1
/ 1
1 1 0 0 0 0 0 ... —1 10 0 0 0 0 ...
2 1 1 0 0 0 0 ... —1 —1 1 0 0 0 0 ...
5 3 1 1 0 0 0 ... —1 —2 — 1 1 0 0 0 ...
= , (83)
15 9 4 1 1 0 0 ... —1 —3 —3 —1 1 0 0 ...
52 31 14 5 1 1 0 ... —1 —4 —6 —4 —1 1 0 ...
203 121 54 20 6 1 1 ... —1 —5 —10 —10 —5 —1 1 ...
\ • • • • • • • • •• • • • •
with rows and columns numbered from 0. The numbers an0 in the left column,
which solve (82) when vn = d',,0, are the familiar Bell numbers ron; they enumer
ate the leaves in the search tree. The numbers an1 in the next column, which solve
(82) when vn = Jn1, are the Gould numbers ~„: they enumerate set partitions
whose last block or “tail” is a singleton, when the blocks of the partition are
ordered by their least elements. In general, ank for k > 0 is the number of set
July 26, 2019
38 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
partitions whose tail has size k. [See H. W. Gould and J. Quaintance, Applicable Quaintance
Gompertz
Analysis and Discrete Mathematics 1 (2007), 371-385.] Euler-Gompertz constant
Exercise 186 proves that the actual number of updates at level 0 is X2C problem
X3C problem
vn = ((9n — 27)4n — (8n — 32)3n + (36n - 36)2n + 72 - 41Jn0)/72; (84) sudoku
X4C problem
and exercise 187 exploits relationships between the sequences tank) to show that perfect matching
matching
complete graph
xn = 22wn + 12wn — (3 n — 1)3n — 2 n2n — 12n — 5 — 12Jn1 — 18Jn0. (85) factoring
Asymptotically, wn/wn converges rapidly to the “Euler-Gompertz constant”
[~ e-xdx . .
g=0 1+x = 0.59634 73623 23194 07434 10784 99369 27937 60741+ (86)
(see exercise 188). Thus xn « (22 + 12g)ron « 29.I56~,,. and we’ve proved that
Algorithm X performs approximately 29.156 updates per solution to the extreme
exact cover problem, on average. That’s encouraging: One might suspect that
the list manipulations needed to deal with 2n options of average length n would
cost substantially more, but the dancing-links approach turns out to be within
a constant factor of Section 7.2.1.5’s highly tuned methods for set partitions.
*Analysis of matching problems. Among the simplest exact cover problems
are the ones whose options don’t contain many items. For example, a so-called
X2C problem (“exact cover with 2-sets”) is the special case where every option
has exactly 2 items; an X3C problem has 3 items per option; and so on. We’ve
seen in (30) that sudoku is an X4C problem.
Let’s take a close look at the simplest case, the X2C problems. Despite their
simplicity, we’ll see that such problems actually include many cases of interest.
Every X2C problem corresponds in an obvious way to a graph G, whose vertices v
are the items and whose edges u ——— v are the pairs of items that occur together
in an option ‘u v’. In these terms the X2C problem is the classical task of finding
a perfect matching, namely a set of edges that contains each vertex exactly once.
We shall study efficient algorithms for perfect matching in Section 7.5.5
below. But an interesting question faces us now, in the present section: How
well does our general-purpose Algorithm X compare to the highly tuned special
purpose algorithms that have been developed especially for matching in graphs?
Suppose, for example, that G is the complete graph K2q+1 . In other words,
suppose that there are n = 2q +1 items {0,1,..., 2q}. and that there are m =
(2q+1) = (2q + 1)q options ‘i j’ for 0 < i < j < 2q. This problem clearly has
no solution, because we can’t cover an odd number of points with 2-element
sets! But Algorithm X won’t know this (unless we give it a hint by factoring the
problem appropriately). Thus it’s interesting to see how long Algorithm X will
spin its wheels before giving up on this problem.
In fact the analysis is easy: No matter what item i is chosen in step X3,
the algorithm will split nicely into 2q branches, one for each option ‘i j ’ with
j = i. And each of those branches will be equivalent to the matching problem on
the remaining 2q — 1 items; the remaining options will, in fact, be equivalent to
the complete graph K2q-1. Thus the search tree will have 2q nodes at depth 1,
July 26, 2019
7.2.2.1 DANCING LINKS: ANALYSIS OF MATCHING PROBLEMS 39
(89)
*Maintaining a decent focus. Some backtrack algorithms waste time by trying focus—
MRV
to solve two or more loosely related problems at once. Consider, for example, search tree
the 2DM problem with 7 items {0, 1, . . . , 6} and the following 13 options: exponential behavior
‘0 1’, ‘0 2’, ‘1 4’, ‘1 5’, ‘1 6’, ‘2 4’, ‘2 5’, ‘2 6’, ‘3 4’, ‘3 5’, ‘3 6’, ‘4 5’, ‘4 6’. (90)
Algorithm X, using its MRV heuristic, will branch on item 0, choosing either ‘0 1’
or ‘0 2’; then it will be faced with a three-way branch; and it will evenually con
clude that there’s no solution, after implicitly traversing a 19-node search tree,
(9i)
‘0 1’, ‘0 2’, ‘13 4’, ‘13 5’, ‘14 5’, ‘2 3 4’, ‘2 3 4 5’, ‘2 4 5’, ‘3 4’, ‘3 5’, ‘4 5’, (92)
(93)
d > 0, (94)
T1 T2 Td
where the item chosen for branching in step X3 has d options, and Tk is the direct sum
dominant node
search tree for the reduced problem after the items of the kth option have been Langford pairs
removed. (With the MRV heuristic, d is the minimum length of all active item n queens problem
minimally dominant
lists, and we choose the leftmost item having this value of d.)
The exact cover problem that we get when trying to solve two independent
problems given by matrices A and A is the problem that corresponds to the
direct sum A ф A (see Eq. 7-(4o)). Therefore if T and T' are the corresponding
search trees, we will write T ф T' for the search tree of A ф A', under the MRV
heuristic. (That tree depends only on T and T', not on any other aspects of A
or A'.) If either T or T' is simply a solution node, the rule is simple:
T ф ■ = T; ■ ф T' = T'. (95)
Otherwise T and T' have the form (94), and we have
if d < d';
Ti Ф T' T2 Ф T' ■ ■■ Td Ф T'’
T ф T' = < (96)
if d > d'.
tфT1 tфT2 ... tфTd,’
Dear reader, please work exercise 202 — which is very easy! — before reading
further. That exercise will help you to understand the definition of T ф T'; and
you’ll also see that every node of T ф T' is associated with an ordered pair aa',
where a and a' are nodes of T and T', respectively. These ordered pairs are the
key to the structure of T ф T': If a and a' appear at levels l > 0 and l > 0
of their trees, so that they are reached from the roots by the respective paths
ao — a1 — • • • — al = a and a0 — a^ — • • • — ,9.. = a1', then the parent of
aa' in TфT' is either al- 1 a' or aa'l, - 1. Consequently every ancestor ak of a in T,
for 0 < k < l, occurs in an ancestor aka'k, of aa' in Tф T', for some 0 < k' < l'.
Let deg(a) be the number of children that node a has in a search tree, except
that we define deg(a) = to when a is a solution node. (Equivalently, deg(a) is
the minimum length of an item list, taken over all active items in the subproblem
that corresponds to node a. If a is a solution, there are no active items, hence the
minimum is infinite.) Let’s call a a dominant node if its degree exceeds the degree
of all its proper ancestors. The root node is always dominant, and so is every
solution node. For example, (91) has three dominant nodes, and (93) has four.
In these terms, exercise 205 proves a significant fact about direct sums:
Y pentominoes
Haselgrove
Fig. 73. A 15 x 15 square can be tiled with symmetry reduction
Y pentominoes, by setting up an exact cover sharp preference
problem with one item for each cell and one local equivalence—
option for each placement of a Y. (To elimi
nate the 8-fold symmetry, only 5 of the 40 op
tions for occupying the center cell were per
mitted.) Algorithm X’s first solution, shown
here, was found by branching successively on
the possible ways to fill the cells marked 0, 1,
. . . , 9, a, . . . , z, A, . . . , I.
In general, an exact cover might contain four distinct options а, в, a', в' bipair: A pair of pairs
secondary item
for which a and в are disjoint, a' and в' are disjoint, and perfect matching
complete bipartite graph
a + в = a' + в'. (97) permutations
4-cycle
(The ‘+’ sign here is like ‘U’; it stands for addition of binary vectors, when
options are rows of a 0-1 matrix.) In such cases we say that (a, в; a', в') is a
bipair. Whenever (a, в; a', в'") is a bipair, every solution that contains both a
and в leads to another solution that contains both a' and в', and vice versa.
Thus we can avoid considering half of all such solutions if we exclude one of those
alternatives. And it’s easy to do that: For example, to exclude all cases that
contain both a' and в, we simply introduce a new secondary item, and append
it to options a' and в'•
To illustrate this idea, let’s apply it to the unsolvable toy problem (90).
That problem has many bipairs, but we’ll consider only two of them,
(‘0 1’, ‘2 4’; ‘0 2’, ‘1 4’) and (‘0 1’, ‘2 5’; ‘0 2’, ‘1 5’). (98)
To avoid solutions that contain both ‘0 1’ and ‘2 4’, as well as those that contain
both ‘0 2’ and ‘1 5’, we introduce secondary items A and B, and we extend four
of the options (90) to
‘0 1 A’, ‘0 2 B’, ‘1 5 B’, ‘2 4 A’. (99)
Then the search tree (91) reduces to
(1oo)
Fortunately, however, there’s always a safe and easy way to proceed. We can strong
strong exact covering
assign an arbitrary (but fixed) ordering to the set of all options. Then, if for every binary vector
bipair (а, в; а', в') we always choose the half that contains min(a, в, а', в'), the lexicographically greater
complete graph
choices will be consistent. preprocessing—
More precisely, we can express every bipair in the canonical form kernelization
(а, в; а', в') а < в, а < а', and а' < в’, (102)
with respect to any fixed ordering of the options. An exact covering is called
strong, with respect to a set of such canonical bipairs, if its options don’t include
both а' and в’ for any bipair in that set.
Theorem S. If an exact cover problem has a solution, it has a strong solution.
The algorithm is based entirely on two general principles, used repeatedly generic option
color controls
until they no longer apply: blocked
• An option can be removed if it blocks all uses of some primary item. forces
factoring
• An item can be removed if some primary item always forces it to appear. data structures
More precisely, let o be a generic option ‘i1 i2[:c2] . . . it [:ct]’, where i1 is primary
and the other t - 1 items might have color controls. When Algorithm C deals
with option o, it covers i1 in step C4 and commits the other items in step C5,
thereby removing all options that aren’t compatible with o. If this process causes
some primary item p to lose its last remaining option, we say that p is “blocked”
by o. In such a case o is useless, and we can remove it. For example, ‘d e g’ can be
removed from (6), because it blocks a; ‘1 s4 s6’ can be removed from (17), because
it blocks s3 ; then ‘1 s1 s3’ and ‘2 s2 s5’ also go away, because they block s4 .
That was the first principle mentioned above, the one that removes options.
The item-removing principle is similar, but more dramatic when it applies: Let p
be a primary item, and suppose that p’s options all contain an uncolored instance
of some other item, i. In such a case we say that p “forces” i; and we can remove
item i, because p must be covered in every solution and it carries i along. For
example, a forces d in (6). Hence we can remove item d, shortening the second
and fourth options to just ‘a g’ and ‘a f ’. Further simplifications now arise.
These two principles, blocking and forcing, are by no means a complete
catalog of transformations that could be used to preprocess exact cover problems.
For example, they are incapable of discovering the fact that (38) is a useless
option in the pentomino problem, nor do they discover the simplifications that
we deduced by factoring the Soma cube problem. (See the discussion before (46).)
Exercise 219 discusses yet another way to discard superfluous options.
A “perfect” and “complete” preprocessor would in fact be able to recognize
any problem that has at most one solution. We can’t hope to achieve that, so
we’ve got to stop somewhere. We shall limit ourselves to the removal of blocking
and forcing, because those transformations can be done in polynomial time, and
because no other easily recognizable simplifications are apparent.
Algorithm P discovers all such simplifications by systematically traversing
the given items and options, using the same data structures that were enjoyed by
Algorithm C. It cycles through all items i, trying first to remove i by studying
what happens when i is covered. If that fails, it studies what happens when the
items of options that begin with i are committed. It needs some small variations
of the former ‘cover’ and ‘hide’ operations (compare with (i2)-(ig), (бо)—(5з)):
Set p ^ DLINK(i). While p = i,
cover" (i) = hide"(i) unless COLOR(p) = 0, (1о3)
then set p ^ DLINK(p) and repeat.
Do operation hide(p); but also set S ^ x,
hide"(p) = (1о4)
whenever LEN(x) has been set to 0 and x < N1.
Set p ^ ULINK(i). While p = i,
uncover" (i) = unhide(i) unless COLOR(p) = 0, (1о5)
then set p ^ ULINK(p) and repeat.
July 26, 2019
46 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
Algorithm P (Preprocessing for exact covering). This algorithm reduces a Langford pairs
given XCC problem until no instances of blocking or forcing are present. It uses n queens problem
MacMahon’s triangle problem
the data structures of Algorithm C, together with new global variables C and S . pentominoes
one-sided
P1. [Initialize.] Set the problem up in memory, as in step C1 of Algorithm C.
(Again there are N items, of which N1 are primary.) Also set C ^ 1. If
there’s an item i < N1 with LEN(i) = 0, go to P9.
P2. [Begin a round.] If C = 0, go to P10. Otherwise set C ^ 0, i ^ 1.
P3. [Is item i active?] If i = N, return to P2. Otherwise if LEN(i) = 0, go to P8.
P4. [Cover i.] Set S ^ 0. Use (103) to cover item i. Then go to P7 if S = 0;
otherwise set x ^ DLINK(i).
P5. [Try x.] If x isn’t the leftmost remaining node of its option, go to P6.
Otherwise use the method of exercise 220 to test whether this option blocks
some primary item. If so, set C ^ 1, TOP(x) ^ S, and S ^ x.
P6. [Try again.] Set x ^ DLINK(x), and return to P5 if x = i. Otherwise
uncover item i using (105); use the method of exercise 221 to delete all
options that were stacked in step P5; and go to P8.
P7. [Remove item i.] Uncover item i (which is forced by the primary item S).
Then use the method of exercise 222 to delete or shorten every option that
uses item i. Finally, set C ^ 1, DLINK(i) ^ ULINK(i) ^ i, LEN(i) ^ 0.
P8. [Loop on i.] Set i ^ i + 1 and return to P3.
P9. [Collapse.] Set N ^ 1 and delete all options. (The problem is unsolvable.)
P10. [Finish.] Output the reduced problem, whose items are those for which
LEN(i) > 0 or i = N = 1, and terminate. (See exercise 223.)
How effective is Algorithm P? Well, sometimes it spins its wheels and
finds absolutely nothing to simplify. For example, the options (16) for n Langford
pairs contain no instances of blocking or forcing when n > 5. Neither do the
options for the n queens problem when n > 3. There’s no “excess fat” in those
specifications. In MacMahon’s triangle problem (exercise 126), Algorithm P
needs just 20 megamems to remove 576 of the 1537 options; but the options that
it removes don’t really matter, because Algorithm C traverses exactly the same
search tree, with or without them.
We do gain 10% when we try to pack pentominoes into a 6 x 10 box (exercise
271): Without preprocessing, Algorithm X needs 4.11 Gp to discover all 2339
solutions to that classic task. But Algorithm P needs just 0.19 Gp to remove 235
of the 2032 options, after which Algorithm X finds the same 2339 solutions in
3.52 Gp; so the total time has been reduced to 3.71 Gp. The similar problem of
packing the one-sided pentominoes into a 6 x 15 box has an even bigger payoff:
It has 3308 options without preprocessing, and 15.5 Tp are needed to process
them. But after preprocessing — which costs a mere 260 Mp — there are 3157
options, and the running time has decreased to 13.1 Tp.
The simplifications discovered by Algorithm P for those pentomino problems
involve only blocking (see exercise 225). But more subtle reductions occur in the
July 26, 2019
7.2.2.1 DANCING LINKS: MINIMUM-COST SOLUTIONS 47
Y pentomino problem of Fig. 73. For example, cell 20 is forced by cell 10, in Y pentomino
sudoku solutions
that problem; and in round 2, cell 00 is forced by cell 22. In round 4, cell 61 is self-equivalent
blocked by the option ‘50 51 52 53 62’ — a surprising discovery! Unfortunately, minimum-cost sols—
cost
however, those clever reductions have little effect on the overall running time. Langford pairs
Preprocessing really shines on the problem of exercise 114, which asks for reverse of a string
all sudoku solutions that are self-equivalent when reflected about their main
diagonal. In this case Algorithm P is presented with 5410 options that involve
intricate color controls, on 585 primary items and 90 secondary items. It rapidly
reduces them to just 2426 options, on 506 primaries and 90 secondaries; and
Algorithm C needs only 287 Gp to process the reduced options and to discover
the 30,286,432 solutions. That’s 7.5 times faster than the 2162 Gp it would have
needed without reduction.
Thus, preprocessing is a mixed bag. It might win big, or it might be a waste
of time. We can hedge our bets by allocating a fixed budget — for instance by
deciding that Algorithm P will be allowed to run at most a minute or so. Its
data structures are in a “safe” state at the beginning of step P3; therefore we
can jump from there directly to step P10 if we don’t want to run to completion.
Of course, preprocessing can also be applied to the subproblems that arise
in the midst of a longer computation. A careful balancing of different strategies
might be the key to solving problems that are especially tough.
Minimum-cost solutions. Many of the exact cover problems that we’ve been
studying have few solutions, if any. In such cases our joy is to discover the
rare gems. But in many other cases the problems have solutions galore; and for
such problems we’ve focused our attention so far on the task of minimizing the
amount of time per solution, assuming that all of the solutions are interesting.
A new perspective arises when each option of our problem has been assigned
a nonnegative cost. Then it becomes natural to seek solutions of minimum cost.
And ideally we’d like to do this without examining very many of the high-cost so
lutions at all; they’re basically useless, but a low-cost solution might be priceless.
Fortunately there’s a reasonably simple way to modify our algorithms, so
that they will indeed find minimum-cost solutions rather quickly. But before we
look at the details of those modifications, it will be helpful to look at several
examples of what is possible.
Consider, for instance, the problem of Langford pairs from this point of
view. We observed near the very beginning of Chapter 7 that there are 2L16 =
653,443,600 ways to place the 32 numbers {1, 1, 2, 2, . . . , 16, 16} into an array
a1a2 . . . a32 so that exactly i entries lie between the two occurrences of i, for
1 < i < 16. And we claimed that the pairing displayed in 7-(з), namely
2 3 4 2 1 3 1 4 16 13 15 5 14 7 9 6 11 5 12 10 8 7 6 13 9 16 15 14 11 8 10 12, (106)
is one of 12,016 solutions that maximize the sum Ei 52k=1 kak. Consequently
the reverse of that pairing, namely
12 10 8 11 14 15 16 9 13 6 7 8 10 12 5 11 6 9 7 14 5 15 13 16 4 1 3 1 2 4 3 2, (107)
July 26, 20i9
48 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
is one of 12,016 solutions that minimize £1. We noted in (16) above that Lang 16 queens problem
n queens
ford pairs are the solutions to a simple exact cover problem, whose options ‘i sj sk’ distance, in a plane
represent the assignments aj = i and ak = i. Therefore, if we associate the cost
$(ji + ki) with option ‘i sj sk’, the minimum-cost solutions will be precisely the
Langford pairings that minimize £1 . (See exercise 226.)
One way to minimize the total cost is, of course, to visit all solutions and to
compute the individual sums. But there’s a better way: The min-cost variant
of Algorithm X below, which we shall call Algorithm X$, finds a solution of
cost $3708 and proves its minimality after only 60 gigamems of computation.
That’s more than 36 times faster than the use of plain vanilla Algorithm X,
which needs 2.2 teramems to run through the full set of solutions.
Moreover, Algorithm X$ doesn’t stop there. It actually will compute the K
solutions of least cost, for any given value of K . For example, if we take K =
12500, it needs just 70 gigamems to discover the 12,016 solutions of cost $3708,
together with 484 solutions of the next-lowest cost (which happens to be $3720).
The news is even better when we try to minimize £2 = k2=1 k2ak instead of
3
£1. Algorithm X$ needs just 28 Gp, to prove that the minimum £2 is $68880. And
better yet is the fact, obtained in only 10 G^, that the minimum of ^2k=1 kak
is $37552, obtainable uniquely by the remarkable pairing
16 14 15 9 6 13 5 7 12 10 11 6 5 9 8 7 14 16 15 13 10 12 11 8 4 1 3 1 2 4 3 2, (108)
which also happens to minimize both £1 and £2. (See exercise 229.)
Another classic combinatorial task, the 16 queens problem, provides another
instructive example. We know from previous discussions that there are exactly
14,772,512 ways to place 16 nonattacking queens on a 16 x 16 board. We also
know that Algorithm X needs about 40 Gp, of computation to visit them all,
when we give it options like (23).
Let’s suppose that the cost of placing a queen in cell (i, j) is the distance
from that cell to the center of the board. (If we number the rows and columns
from 1 to 16, that distance d(i, j) is (i - 17/2)2 + (j - 17/2)2; it varies from
d(8, 8) = 1/ 2 to d(1, 1) = 15/ 2.) Thus we want to concentrate the queens
near the center as much as possible, although many of them must lie at or near the
edges because there must be one queen in each row and one queen in each column.
Figure 74(a) shows how to minimize the total cost — and this answer actually XCC problems
prime square
turns out to be unique, except for rotation and reflection. Similarly, Figs. 74(b) preprocessing
and 74(c) show the placements that maximize the cost. (Curiously, those solu Monte Carlo
truncation errors
tions are obtainable from each other by reflecting the middle eight rows, without arithmetic overflow
changing the top four or the bottom four.) Algorithm X$, with K = 9, discovers transp ose
and proves the optimality of those placements in just (a) 3.7 G/<: (b, c) 0.8 G/'..
The modifications that convert Algorithm X to Algorithm X$ also convert
Algorithm C into Algorithm C$. Therefore we can find minimum-cost solutions
to XCC problems, which go well beyond ordinary exact cover problems.
For example, here’s a toy problem that now becomes tractable: Put ten
different 5-digit prime numbers into the rows and columns of a 5 x 5 array, in
such a way that their product is as small as possible. (A 5-digit prime number
is one of the 8363 primes between 10007 and 99991, inclusive.) One such “prime
square,” made up entirely of primes that are less than 30000, is
2 1 2 1 1
2 0 1 0 1
1 1 0 0 3 • (109)
1 1 0 6 9
1 1 1 1 3
To set this up as an XCC problem, introduce ten primary items {a1 , a2, a3,
a4, a5} and {d1, d2, d3, d4, d5} that represent “across” and “down,” together with
25 secondary items ij for 1 < i, j < 5 that represent cells of the array, together
with 8363 additional secondary items p1p2p3p4p5 , one for eligible prime p =
p1p2p3p4p5 . The options for placing p in row i or column j are then
‘ai i1:p1 i2:p2 i3:p3 i4:p4 i5:p5 p1p2p3p4p5’;
(no)
‘dj 1j:p1 2j:p2 3j:p3 4j:p4 5j:p5 p1p2p3p4p5’.
For example, ‘a4 41:1 42:1 43:0 44:6 45:9 11069’ enables the prime 11069 in (109).
This is a good example where preprocessing is helpful, because the primes
that are usable in a1 and d1 must not contain a 0; furthermore, the primes that
are usable in a5 and d5 must contain only the digits {1, 3, 7, 9}. Algorithm P
discovers those facts on its own, without being told anything special about
number theory. It reduces the 83630 options of (11o) to only 62900; and those
reductions provide useful clues for the choices of items on which to branch.
The Monte Carlo estimate of exercise 86 tells us that there are roughly
6 x 1014 different ways to fit ten primes into a 5 x 5 array — a vast number. We
probably don’t need to look at too many of those possibilities, yet it isn’t easy
to decide which of them can safely be left unexamined.
To minimize the product of the primes, we assign the cost $(ln p) to each of
the options in (11o). (This works because the logarithm of a product is the sum
of the logarithms of the factors.) More precisely, we use the cost $ |_Clnp_|, where
C is large enough to make truncation errors negligible, but not large enough to
cause arithmetic overflow, because Algorithm C$ wants all costs to be integers.
Every solution has the same cost as its transpose. Thus we can get the best
five prime squares by asking Algorithm C$ to compute the K = 10 least-cost
July 26, 2019
50 combinatorial searching (f5c: 26 Jul 2019 @ 2051) 7.2.2.1
solutions, each of which occurs twice. Here they are, with the best at the left: preprocessing
USA
1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 contiguous states
planar graph
1 0 1 0 3 1 0 1 0 3 1 0 0 0 7 1 0 0 0 7 1 0 0 0 7 exact cover problem
1 1 0 0 3 1 1 0 0 3 1 1 0 0 3 1 1 0 0 3 1 1 0 0 3 • (111) exterior cost
3 1 7 6 9 3 1 7 7 1 3 1 6 9 9 3 1 6 6 3 3 1 6 6 3
1 1 1 7 1 1 1 1 9 7 1 1 1 1 7 1 1 1 7 7 1 1 1 9 7
The running time, 440 Gp, would have been 1270 Gp without preprocessing; so
the 280 Gp spent in preprocessing paid off. But the five greatest-cost solutions,
(113)
define an interesting planar graph that has already supplied us with a variety of
instructive examples. This graph G has 48 vertices and 105 edges. Suppose we
want to partition it into eight connected subgraphs of six vertices each. What’s
the minimum number of edges whose removal will do that?
Well, exercise 7.2.2-76 has told us how to list all of the connected subsets of
six states, and there happen to be 11505 of them. That gives us 11505 options for
an exact cover problem on 48 items, whose solutions are precisely the potential
partitions of interest. The total number of solutions turns out to be 4,536,539;
and Algorithm X is able to visit them all, at a cost of 807 gigamems.
But let’s try to do better, using Algorithm X$. Every induced subgraph G | U
has an exterior cost, which is the number of edges from U to vertices not in U .
When we partition a graph by removing edges, every such edge contributes to the
exterior cost of two of the components that remain; hence the number of removed
edges is exactly half the sum of the exterior costs. The best partition therefore
corresponds to the minimum-cost solution to our exact cover problem, if we
assign the exterior costs to each option. For example, one of the 11505 options is
Before we look at the answer, let’s stare at the problem a bit longer, because New England
census data
we still haven’t discovered the best way to solve it! A closer examination population
shows that option (114) is useless, because it could never actually appear in
any solution: It cuts the graph into two pieces, with 11 states to the left and
31 states to the right. (We encountered a similar situation earlier in (38).) In
fact, 4961 of the 11505 options turn out to be unusable, for essentially the same
reason. The state of Maine (ME), for example, belongs of 25 connected subgraphs
of order 6; but we can easily see that the only way to get ME into the final partition
is to group it with the other five states of New England (NH, VT, MA, CT, RI).
Exercise 242 explains how to detect and reject the useless options quickly.
The remaining problem, which has 6544 options, is solved by Algorithm X
in 327 Gp and by Algorithm X$ in just 1046 Mp.
Essentially the same methods will partition the graph nicely into six con
nected clusters of order eight. This time the exact cover problem has 40520
options after reduction, and a total of 4,177,616 solutions. But Algorithm X$
needs less than 2 Gp to determine the minimum cost, which is $54.
Here are examples of the optimum partitions found, 8 x 6 and 6 x 8:
SD WI MI
IL IN OH PA
KY WV MD
VA
(115)
GA
In each case the optimum can actually be achieved in two ways: On the left, one
could swap the affiliations of VA and WV; on the right, a more complicated cyclic
shuffle (MI NE LA VA) could be used.
It’s also instructive to solve a different kind of problem, namely to use census
data and to partition G based on the population of each state. For example, let’s
try to find eight connected clusters that each contain nearly the same number
of people. The total population, P, of the 48 states was officially 306084180 in
2010. We want each cluster to represent P/8 people, or as close to P/8 as we
can get. That’s about 38 million people per cluster.
The algorithm of exercise 242 will find and reduce all connected subgraphs
whose total population x satisfies L < x < U, for any given bounds L and U. If
we take L > [P/9J (which is about 34 million) and U < \P/T\ (which is about
44 million), those candidate subgraphs will define an exact cover problem for
which every solution uses exactly eight options, because 9x > P and 7x < P.
That algorithm proves that G contains 1,926,811 connected sets of states
whose population lies in [34009354 . . 43726312); and it prunes away 1,571,057 of
them, leaving 355,754. But that’s overkill. This problem has enough flexibility
that its final solution can be expected to contain only sets whose population is
quite close to 38 million. Therefore we might as well restrict ourselves to the
range [37000000 . . 39000000) instead. There are 34,111 such options; surely they
should be enough to solve our problem.
July 26, 2019
52 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
Well, that’s very plausible, but unfortunately it doesn’t work: Those 34,111 articulation point
New York
options have no solution, because Algorithm X can’t use them to cover NY (New New England
York)! Notice that NY is an articulation point of G. The population of New pi as source
York is about 19.4 million, and the combined population of the six New England
states is about 14.3 million. Whatever option covers New York had better cover
all of New England too, otherwise New England is stranded. So that makes
19.4 + 14.3 = 33.7 million people. New York’s only other neighbors are New
Jersey (8.8 million) and Pennsylvania (12.7 million); adding either of them will
put us over 42 million.
So we’re clearly not going to be able to cover New York with a cluster that’s
close to the desired 38 million. We’ll either need a lightweight one (New York
plus New England) or a heavyweight one (with New Jersey too). Let’s throw
those two options in with the other 34,111.
Notice that this problem is quite different from the others we’ve been dis
cussing, because its options vary greatly in size. One of the options contains just
one state, CA (California), whose population is the largest (37.3 million); others
contain up to fifteen states, almost spanning the continent from DE to NV.
Now we assign the cost $(x2) to each option with population x, because the
minimum-cost solutions will then minimize the squared deviations (x1 - P/8)2 +
• • • + (x8 — P/8)2. (See exercise 243.) This works well; and Algorithm X$ needs
only 3.3 gigamems to find the optimum solution below. The seven options not
involving New York all contain between 37.3 and 38.1 million people.
A similar analysis, partitioning into six equipopulated clusters instead of
eight, gives in 1.1 Gp, a minimum-cost solution whose six populations are all in
the range [50650000 . . 51150000]. Both solutions are illustrated here, with the
area of each vertex proportional to its population:
In both cases the solution is unique. (And in both cases, let’s face it, the solution
is also pretty weird. Partitions like this could only be concocted by a computer.
Exercise 246 discusses approximate solutions that are less eccentric.)
*Implementing the min-cost cutoffs. OK, we’ve now seen lots of reasons why
Algorithms X$ and C$ are desirable. But how exactly can we obtain those algo
rithms by extending Algorithm X and C? It will suffice to describe Algorithm C$.
The mission of Algorithm C$ is to find the K min-cost solutions. More
precisely, it should discover K solutions whose total cost is as small as possible,
with the understanding that different solutions might have the same cost. Let’s
imagine, for example, a problem that has exactly ten solutions, and that their
costs are $3, $1, $4, $1, $5, $9, $2, $6, $5, $3, in the order that Algorithm C would
July 26, 2019
7.2.2.1 DANCING LINKS: IMPLEMENTING THE MIN-COST CUTOFFS 53
discover them. Algorithm C$ won’t differ from Algorithm C until it has found K BEST
heap ordered
solutions, because those K might turn out to be the best. After K are known, cutoff value
however, it will be harder to please: It will accept a new solution only if that so COST
covering
lution is better than one of the best K it knows. Thus if K = 3, say, the accepted purifying
solutions will have costs $3, $1, $4, $1, $2; Algorithm C$ won’t find the other five. uncovering
unpurifying
To implement that behavior, we maintain a BEST table, which contains the threshold
K least costs known so far. That table is “heap ordered,” with unhiding
hiding
BEST[ [j'/2j ] > BEST[j] for 1 < |_j/2j < j < K (117) dancing links
backtracking
(see Eq. 5.2.3-(з)). In particular, BEST[1] will be the greatest of the least K
costs, and we call it the cutoff value, T . Algorithm C$ will reject any solution
whose cost is T or more. Initially, BEST[j] = to for 1 < j < K; then every new
solution of cost c < T will be “sifted” into the BEST table as in Algorithm 5.2.3H.
The successive cutoff values in the example above, if K = 3, would therefore be
to, to, 4, 3, 3, 3, 2, 2, 2, 2. If K = 4 they’d be to, to, to, 4, 4, 4, 3, 3, 3, 3.
Algorithm C$ adds a COST field to every node, thereby making each node
64 bits larger than before. Step C1$ stores the cost of every option, assumed to
be a nonnegative integer, in each node belonging to that option.
The costs in every list of options created by step C1$ are ordered, so that
be different each time. Step C5$ should go directly to C7$ if 0 < 0. Otherwise author
it sets TH[l] ^ 0 in that step, and uses TH[l] for undoing in step C6$, where MRV heuristic
square of primes
TH is another auxiliary array. n queens problem
contiguous USA
Step C3$, which chooses the item on which to branch at level l, is of course Langford pair
crucially important. If some primary item i has no options, or if the cost of its pentomino
preprocessing the costs
least expensive option is so high that it can’t lead to a solution better than we’ve marginal costs
already found, step C3$ should jump immediately to step C8$. Otherwise, many tax
author
strategies are worthy of investigation, and there’s room here to discuss only the
method that was used in the author’s experiments: Good results were obtained
by choosing an i with the fewest not-too-costly options, as in the MRV heuristic.
In case of ties, the author’s implementation chose an i whose least expensive
option cost the most. (That item must be covered sooner or later, so there’s no
way to avoid paying that much. We probably have a better chance of reaching a
cutoff quickly if we maximize our chances of failure.) Exercise 248 has full details.
Many applications of Algorithm C$ have special features that allow us to
prune unproductive branches from the search tree long before they would be cut
off by the methods discussed so far. For example, every option in our “square
of primes” problem has exactly one primary item (see (no)). In such cases, we
know that every solution obtained by extending x0 . . . xl-1 must cost at least
*Dancing with ZDDs. The solutions visited by Algorithm X in step X2 can be ZDDs
bipair
represented naturally in the form of a decision tree, as we discussed in Section
7.1.4. For example, here’s a decision tree for the solutions to the problem of
covering the eight cells of a 3 x 3 board with four dominoes, after the corner
cell 22 has been removed:
(120)
This diagram uses the standard ZDD conventions: Every branch node names an
option. A solid line means that the option is taken, while a broken line means
that it is not. The terminal nodes ± and T represent failure and success. This
problem has four solutions, corresponding to the four paths from the root to T.
We learned in Section 7.1.4 that ZDDs can readily be manipulated, and
that a small ZDD can sometimes characterize a large family of solutions. If
we’re lucky, we can save a huge amount of time and energy by simply generating
an appropriate ZDD instead of visiting the solutions one by one.
Such economies arise when the same subproblem occurs repeatedly. For
example, two branches come together in (120) at the node marked ‘*’; this
happens because the problem that remains after placing two dominoes ‘00 10’
and ‘01 11’ is the same as the residual problem after placing ‘00 01’ and ‘10 11’.
“We’ve been there and done that.” Hence we needn’t recapitulate our former
actions, if we’ve already built a subZDD to remember what we did. (Those two
pairs of domino placements form a “bipair,” as discussed earlier; but the ZDD
idea is considerably more general and powerful.)
Let’s look more closely at the underlying details. The exact cover problem
solved by (120) has eight items 00, 01, 10, 02, 11, 20, 12, 21, representing cells to
be covered; and it has the following ten options, representing domino placements:
1:00 01 3:01 02 5:02 12 7:10 20 9:11 21
(121)
2:00 10 4:01 11 6:10 11 8:11 12 10: 20 21
where 0 and 1 stand for ± and T. (See, for instance, 7.1.4-(8).) “If we don’t take
option 2, go to instruction 8; but if we do take it, continue with instruction 11.”
July 26, 2019
56 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
problem has N primary items {1,...,N}, and (N^) options ‘j k’ for 1 < j < Fibonacci number
k < N. We noted earlier, in the discussion preceding (87), that every item
list on level l has exactly N - 1 - 2l options, regardless of the choices made in
step Z3. If we always choose the smallest uncovered item, step Z2 will compute
exactly Nl-l different signatures on level l, namely the signatures in which items
{1,..., 1} are covered and so are 1 of the other items {1 + 1,..., N}. Hence the
total number of cache entries is lN=0 Nl-l = FN +1, a Fibonacci number(!). (See
exercise 1.2.8-16.) Moreover, the main loops in steps Z5 and Z6 are executed
(N- 1 - 2l) Nl-l times at level l, since steps Z3 and Z4 are executed Nl-l times.
In fact, when N is even, the ZDD that is output for all perfect matchings
of KN turns out to have exactly lN=0 (N -1-2l) Nl-l + 2 nodes, which is ap
proximately N5 FN +1 . Exercise 255 shows that the total running time to compute
this ZDD is ©(N2FN) = ©(N2фл'); and the same estimate holds also when N
is odd and the ZDD has only one node ‘±’. This is much smaller than the time
needed by Algorithm X, which is © (N/e)N/2 .
More concretely, Algorithm X computes the 2,027,025 perfect matchings
of K16 in about 360 megamems, using about 6 kilobytes of memory. Algorithm Z
needs only about 2 megamems to characterize those matchings with a 10,228-
node ZDD; but it uses 2.5 megabytes of memory. For K32 there are 191,898,
783,962,510,625 perfect matchings, and the difference is even more dramatic:
Algorithm X costs about 34 thousand petamems and 25 kilobytes; Algorithm Z
costs about 16 gigamems and 85 megabytes, for a ZDD with 48 meganodes.
This example illustrates several important points: (1) Algorithm Z can
greatly reduce the running time of Algorithm X (or Algorithm C), trading time
for space. (2) These improvements can also be achieved for problems that have
no solutions, like matchings of K2q+1 . (3) The number of nodes in the ZDD that
is output might greatly exceed the number of memos in Algorithm Z’s cache.
Let’s take a closer look at the ZDDs. The output for N = 8 is, schematically,
00111010 00011000)
in this
00010100
diagram
a
00110110
00010010 o=3\ в
00110101
Y
00010001 stands for
00101110 three
00001100
branch
(11111111 00101101
nodes (123)
00001010
00101011
a
00001001)
00011110 в
00000110
00011101
Y
00000101
(00111111 00011011
00010111 00000011)
00001111
where, for example, ‘(00101101)’ represents nodes for the signature 00101101.
July 26, 2019
58 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
Indeed, the general XCC problem, “exact covering with colors,” has a truly XCC problem
options
extraordinary number of applications. The exercises below exhibit dozens and items
dozens of instructive problems that are quite naturally describable in terms of MCC problem
Historical notes
“options,” which involve “items” that may or may not be colored in certain Hitotumatu
ways. We’ve discussed Algorithm X (for XC problems) and Algorithm C (for Noshita
XCC problems); and the good news is that those algorithms are almost identical. n queens problem
Rohl
Furthermore, we’ve seen how to extend Algorithm C in several directions: singly linked lists
author
Algorithm M handles the general MCC problem, which allows items to be covered Hoare
with different ranges of multiplicities. Algorithm C$ associates a cost with each DLX
de Bruijn
option, and finds XCC solutions of minimum total cost. Algorithm Z produces Huang
XCC solutions as ZDDs, which can be manipulated and optimized in other ways. exact cover problems
Pierce
Garfinkel
Historical notes. The basic idea of (2) was introduced by H. Hitotumatu and Nemhauser
cost
K. Noshita [Information Processing Letters 8 (1979), 174-175], who applied it minimum-cost solutions
to the n queens problem. Algorithm 7.2.1.2X, which was published by J. S. Rohl operations research
rows
in 1983, can be regarded as a simplified version of dancing links, for cases when columns
singly linked lists suffice. (Indeed, as Rohl observed, the n queens problem is items
options
such a case.) Its extension to exact cover problems in general, as in Algorithm X dancing with ZDDs
above, was the subject of the author’s tribute to C. A. R. Hoare in Millennial Nishino
Yasuda
Perspectives in Computer Science (2000), 187-214, where numerous examples Minato
were given. [That paper was subsequently reprinted with additions and correc Nagata
tions as Chapter 38 of FGbook.] His original implementation, called DLX, used
a more complex data structure than (10), involving nodes with four-way links.
Knuth extended Algorithm X to Algorithm C in November 2000, while
thinking about two-dimensional de Bruijn sequences. A special case of Algo
rithm M, in which all multiplicities are fixed, followed in August 2004, when he
was thinking about packing various sizes of bricks into boxes. The current form of
Algorithm M was developed in January 2017, after he’d studied an independent
generalization of Algorithm X that Wei-Hwa Huang had written in 2007.
The first computer programs for exact cover problems were developed in
dependently by J. F. Pierce [Management Science 15 (1968), 191-209] and by
R. S. Garfinkel and G. L. Nemhauser [Operations Research 17 (1969), 848-856].
In both cases the given options each had an associated cost, and the goal was to
obtain minimum-cost solutions instead of arbitrary solutions. Both algorithms
were similar, although they used different ways to prune nonoptimum choices:
Items were chosen for branching according to a fixed, precomputed order, and
options were represented as bit vectors. An option was never removed from its
item list; it would repeatedly be rejected if its bits intersected with previously
chosen items. (Caution: Literature from the operations research community
traditionally reverses the roles of rows and columns in matrices like (5). For them,
items are rows and options are columns, even though bit vectors look like rows.)
The concept of “dancing with ZDDs” was introduced by M. Nishino, N. Ya
suda, S. Minato, and M. Nagata, in the AAAI Conference on Artificial Intelli
gence 31 (2017), 868-874, where they presented the special case of Algorithm Z
in which all items are primary.
July 26, 2019
60 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
The history of XCC solving is clearly still in its infancy, and much more work focus
factoring
needs to be done. For example, many applications will benefit from improved ZDD
ways to choose an item for branching — especially in step M3 of Algorithm M, weight
matrix
where only a few strategies have been explored so far. It’s important to maintain 0s and 1s
a good “focus”; furthermore, techniques of “factoring” can dramatically prune doubly linked list
away unproductive branches, as shown for example in exercise 343. list head
LLINK
Algorithm M deserves to be extended to Algorithm M$, and perhaps also to RLINK
delete
produce ZDD output. A further generalization would be to allow each item of permutation
each option to have an associated weight. (Thus the associated matrix, analogous binary search tree
undelete
to (б), would not consist merely of 0s and 1s.) linear equations
Hence we can expect to see many continued advances in XCC solving. incidence matrix
0—1 matrices
families of sets
EXERCISES — First Set partition
tiling
► 1. [M25] A doubly linked list of n elements, with a list head at 0, begins with
LLINK(k) = k - 1 and RLINK(k - 1) = k for 1 < k < n; furthermore LLINK(0) = n
and RLINK(n) = 0, as in (3). But after we use operation (1) to delete elements a1, a2,
. . . , an, where a1a2 . . . an is a permutation of {1, 2, . . . , n}, the list will be empty and
the links will be entangled as in (4).
a) Show that the final settings of llink and rlink can be described in terms of the
binary search tree that is obtained when the keys an , . . . , a2 , a1 (in reverse order)
are inserted by Algorithm 6.2.2T into an initially empty tree.
b) Say that permutations a1a2 . . . an and b1b2 . . . bn are equivalent if they both yield
the same llink and rlink values after deletion. How many distinct equivalence
classes arise, for a given value of n?
c) How many of those equivalence classes contain just one permutation?
2. [M30] Continuing exercise 1, we know that the original list will be restored if we
use (2) to undelete the elements an, ... , a2, a1, reversing the order of deletion.
a) Prove that it’s restored also if we use the unreversed order a1 , a2 , . . . , an (!).
b) Is the original list restored if we undelete the elements in any order whatsoever?
c) What if we delete only k of the elements, say (a1, . . . , ak), then undelete them in
the same order (a1 , . . . , ak). Is the list always restored?
3. [20] An m x n matrix that’s supposed to be exactly covered can be regarded as
a set of n simultaneous equations in m unknowns. For example, (5) is equivalent to
x2 + x4 = x3 + x5 = x1 + x3 = x2 + x4 + x6 = x1 + x6 = x3 + x4 = x2 + x5 + x6 = 1,
18. [10] What are the solutions to (6) if items e, f, and g are secondary? secondary
options without primary items
► 19. [21 ] Modify Algorithm X so that it doesn’t require the presence of any primary pairwise ordering
items in the options. A valid solution should not contain any purely secondary options; binary notation
ruler function p
but it must intersect every such option. (For example, if only items a and b of (6) were k-wise ordering
primary, the only valid solution would be to choose options ‘a d g’ and ‘b c f’.) unsymmetrical
symmetry breaking
► 20. [25] Generalize (26) to a pairwise ordering of options (a0,... , am-1; во, ■ ■ ■ , em-1) canonical solutions
that uses at most |"lg m"| of the secondary items y1, ... , ym-1 in each option. Hint: diagonal
diagonal
Think of binary notation, and use yj at most 2pj times within each of the a’s and e's. central symmetry
21. [22] Extend exercise 20 to k-wise ordering of km options aj, for 1 < i < k and 90-deg rot symmetry
queen graph
0 < j < m. The solutions should be (j,..., ajk) with 0 < j1 < • • • < jk < m. colored
Again there should be at most |"lg m"| secondary items in each option. balanced
secondary items
► 22. [28] Most of the solutions to the n queens problem are unsymmetrical, hence they Langford’s problem
lead to seven other solutions when rotated and/or reflected. In each of the following completion ratio
0—1 matrix
cases, use pairwise encoding to reduce the number of solutions by a factor of 8. backtrack tree
a) No queen is in either diagonal, and n is odd. MRV
order of primary items
b) Only one of the two diagonals contains a queen. (a) (b) (c) randomize
c) There are two queens in the two diagonals. MRV
23. [28] Use pairwise encoding to reduce the number of solutions by nearly a factor
of 8 in the remaining cases not covered by exercise 22:
a) No queen is in either diagonal, and n is even.
b) A queen is in the center of the board, and n is odd.
24. [20] With Algorithm X, find all solutions to the n queens problem that are
unchanged when they’re rotated by (a) 180°; (b) 90°.
25. [20] By setting up an exact cover problem and solving it with Algorithm X, show
that the queen graph Q8 (exercise 7.1.4-241) cannot be colored with eight colors.
26. [21] In how many ways can the queen graph Q8 be colored in a “balanced” fashion,
using eight queens of color 0 and seven each of colors 1 to 8?
27. [22] Introduce secondary items cleverly into the options (16), so that only planar
solutions to Langford’s problem are obtained. (See exercise 7-8.)
28. [M22] For what integers c0, t0, c1 , t1, . . . , cl , tl with 1 < cj < tj does the text’s
formula (27) for estimated completion ratio give the value (a) 1/2? (b) 1/3?
► 29. [26] Let T be any tree. Construct the 0-1 matrix of an unsolvable exact cover
problem for which T is the backtrack tree traversed by Algorithm X with the MRV
heuristic. (A unique item should have the minimum len value whenever step X3 is
encountered.) Illustrate your construction when T = /\.
30. [25] Continuing exercise 29, let T be a tree in which certain leaves have been
distinguished from the others and designated as “solutions.” Can all such trees arise
as backtrack trees in Algorithm X?
31. [M21 ] The running time of Algorithm X depends on the order of primary items
in the active list, as well as on the order of options in the individual item lists. Explain
how to randomize the algorithm so that (a) every item list is in random order after
step X1; (b) step X3 chooses randomly among items with the minimum len.
32. [M21 ] The solution to an exact cover problem with M options can be regarded as
a binary vector x = x1 . . . xM, with xk = [choose option k]. The distance between two
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—FIRST SET 63
solutions x and x' can then be defined as the Hamming distance d(x, x') = v(x©x'), the distance
number of places where x and x differ. The diversity of the problem is the minimum dis Hamming distance
diversity
tance between two of its solutions. (If there’s at most one solution, the diversity is to.) uniform
a) Is it possible to have diversity 1? quasi-uniform
polyomino
b) Is it possible to have diversity 2? polycube
c) Is it possible to have diversity 3? 0-1
d) Prove that the distance between solutions of a uniform exact cover problem — that NP-hard
unique solution
is, a problem having the same number of items in each option — is always even. lexicographic order
e) Most of the exact cover problems that arise in applications are at least quasi MRV heuristic
queens
uniform, in the sense that they have a nonempty subset of primary items such Sloane
that the problem is uniform when restricted to only those items. (For example, to queens
every polyomino or polycube packing problem is quasi-uniform, because every golden ratio
greedy queens
option specifies exactly one piece name.) Can such problems have odd distances? random exact cover problems
exact cover problem
33. [M16] Given an exact cover problem, specified by a 0-1 matrix A, construct an bitwise manipulation
exact cover problem A that has exactly one more solution than A does. [Consequently breadth-first
it is NP-hard to determine whether an exact cover problem with at least one solution 0s and 1s
primary items
has more than one solution.] Assume that A contains no all-zero rows.
34. [M25] Given an exact cover problem A as in exercise 33, construct an exact cover
problem A such that (i) A has at most three 1s in every column; (ii) A and A have
exactly the same number of solutions.
35. [M21 ] Continuing exercise 34, construct A having exactly three 1s per column.
► 36. [25] Let ik = TOP(xk) be the item on which branching occurs at level k in Algo
rithm X. Modify that algorithm so that it finds the solution for which i0x0i1x1i2x2 . . .
is smallest in lexicographic order. (It’s easy to do this by simply setting i ^ RLINK(0)
in step X3. But there’s a much faster way, by using the MRV heuristic most of the time.)
What is the lexicographically first solution to the 32 queens problem?
37. [M46] (N. J. A. Sloane, 2016.) Let {qn) be the lexicographically smallest solution
to the to queens problem. (This sequence begins
1, 3, 5, 2, 4, 9, 11, 13, 15, 6, 8, 19, 7, 22, 10, 25, 27, 29, 31, 12, 14, 35, 37, 39, 41, 16, 18, 45, . . . ,
51. [22] In how many ways can (29c) be completed so that every row, every column, multiset
and every box contains a permutation of the multiset {1, 2, 3, 4, 5, 6, 7, 7, 9}? sudoku puzzle
hardest puzzle
52. [40] Try to find a sudoku puzzle that’s as difficult as possible for Algorithm X. shidoku
McGuire
53. [M26] Beginners to sudoku might want to cut their teeth on a miniature variant trios
called shidoku, which features 4 x 4 squares divided into four 2 x 2 boxes. minirows of sudoku: see trios
Thoen
a) Prove that every uniquely solvable shidoku problem has at least four clues. van de Wetering
b) Two shidoku problems are equivalent if we can get from one to the other by sudoku solutions
9 queens problem
permuting rows and columns in such a way that boxes are preserved, and/or by jigsaw sudokus
90° rotation, and/or by permuting the numbers. Show that there are exactly 13 Puzzlium Sudoku ABC
essentially different 4-clue shidoku problems. hexomino
alphabet
► 54. [35] (Minimal clues.) Puzzle (29a) contains more clues than necessary to make Behrens
gerechte design
the sudoku solution unique. (For example, the final ‘95’ could be omitted.) Find all n-ominoes
subsets X of those 32 clues for which (i) the solution is unique, given X; yet also (ii) for boxes
every x G X, the solution is not unique, given X \ x. rainbow
55. [34] (G. McGuire.) Prove that at least 18 clues are necessary, in any sudoku
puzzle whose unique answer is (28a). Also find 18 clues that suffice. Hint: At least
two of the nine appearances of {1, 4, 7} in the top three rows must be among the clues.
Similarly, find a smallest-possible set of clues whose unique answer is (28b).
56. [47] What is the largest number of clues in a minimal sudoku puzzle?
57. [22] Every sudoku solution has 27 horizontal trios and 27 vertical trios, namely
the 3-digit sets that appear within a single row or column of a box. For example, (28a)
has nine horizontal trios {1, 2, 3}, {2, 3, 4}, . . . , {9, 1, 2} and three vertical trios {1, 4, 7},
{2, 5, 8}, {3, 6, 9}; (28b) has just three of each. The solution to (29a) has 26 horizontal
trios and 23 vertical trios; {3, 6, 8} occurs once horizontally and twice vertically.
Let T be the 27 trios {{A, B, C} | A G {1, 2, 3}, B G {4, 5, 6}, C G {7, 8, 9}}. Find all
sudoku solutions whose horizontal trios and vertical trios are both equal to T .
► 58. [22] (A. Thoen and A. van de Wetering, 2019.) Find all sudoku solutions for
which the 1s, 2s, . . . , 7s also solve the nine queens problem.
59. [20] Solve the jigsaw sudokus in (34). How large is Algorithm X’s search tree?
60. [20] (The Puzzlium Sudoku ABC.) Complete these hexomino-shaped boxes:
► 62. [34] For n < 7, generate all of the ways in which an nxn square can be packed with
n nonstraight n-ominoes. (These are the possible arrangements of boxes in a square
jigsaw sudoku.) How many of them are symmetric? Hint: See exercise 7.2.2-76.
63. [29] In how many different ways can Behrens’s 9 x 9 array (35c) be regarded as
a gerechte latin square? (In other words, how many decompositions of that square
into nine boxes of size 9 have a complete “rainbow” {1, 2, 3, 4, 5, 6, 7, 8, 9} in each box?
None of the boxes should simply be an entire row or an entire column.)
July 26, 2019
66 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
64. [23] (Clueless jigsaw sudoku.) A jigsaw sudoku puzzle can be called “clueless” Clueless jigsaw sudoku
if its solution is uniquely determined by the entries in a single row or Maxime
A B C D E F jigsaw sudoku
column, because such clues merely assign names to the n individual sudoku
symbols that appear. For example, the first such puzzle to be pub Hypersudoku
NRC Sudoku, see hypersudoku
lished, discovered in 2000 by Oriel Maxime, is shown here. rainbow
a) Find all clueless sudoku jigsaw puzzles of order n < 6. Ritmeester
b) Prove that such puzzles exist of all orders n > 4. pi as random data
polyomino
65. [24] Find the unique solutions to the following examples of jigsaw sudoku: bounding box
convex polyominoes
pentominoes
enneominoes, see nonominoes
► 66. [30] Arrange the following sets of nine cards in a 3 x 3 array so that they define
a sudoku problem with a unique solution. (Don’t rotate them.)
i)
ii)
► 67. [22] Hypersudoku extends normal sudoku by adding four more (shaded) boxes in
which a complete “rainbow” {1, 2, 3, 4, 5, 6, 7, 8, 9} is required to appear:
► 69. [30] Diagram (i) below shows the 81 communities of Bitland, and their nine elec Bitland
toral districts. The voters in each community are either Big-Endian (B) or Little-Endian voters
parliament
(L). Each district has a representative in Bitland’s parliament, based on a majority vote. redistricting
Notice that there are five Ls and four Bs in every district, hence the parliament is political districting
gerrymander
100% Little-Endian. Everybody agrees that this is unfair. So you have been hired as Gerry
a computer consultant, to engineer the redistricting. politics
A rich bigwig secretly offers to pay you a truckload of money if you get the best convex
nonomino
possible deal for his side. You could gerrymander the districts as in diagram (ii), Dominosa
thereby obtaining seven Big-Endian seats. But that would be too blatantly biased. solitaire
game
B B L B L L L L B B B L B L L L L B Pijanowski solitaire, see Dominosa
L L L B L L L B L L L L B L L L B L dominoes
B B L B L B B L B B B L B L B B L B 3D MATCHING
L L L L L L L L L L L L L L L L L L permutations of the multiset
(i) B B B L L B L L B (ii) B B B L L B L L B random domino placement
L B L B B B B B B L B L B B B B B B
B B L B B B B B L B B L B B B B B L
L B L L L L B L L L B L L L L B L L
L L B L L B B L L L L B L L B B L L
Show that seven wins for B are actually obtainable with nine districts that do
respect the local neighborhoods of Bitland quite decently, because each of them is a
convex nonomino that fits in a 4 x 4 square (see exercise 68).
70. [21] Dominosa is a solitaire game in which you “shuffle” the 28 pieces ,
, ..., of double-six dominoes and place them at random into a 7 x 8 frame.
Then you write down the number of spots in each cell, put the dominoes away, and try
to reconstruct their positions based only on that 7 x 8 array of numbers. For example,
sehihm (0 6 5 2 1 4 1 2\
I 1
1
4
1
5
5
3
6
5
0
3
0
3
4
6
4
yields the array 4 4 5 6 2 2 2 3
0 0 5 6 1 3 3 6
6 6 2 0 3 2 5 1
1 5 0 4 4 0 3 2
a) Show that another placement of dominoes also yields the same matrix of numbers.
b) What domino placement yields the array
/3 3 6 5 1 5 1 5\
65612324
24333620
41614460 ?
3 0 3 0 1 1 4 4
26250500
25054216
► 71. [20] Show that Dominosa reconstruction is a special case of 3D MATCHING.
72. [M22] Generate random instances of Dominosa, and estimate the probability of
obtaining a 7x8 matrix with a unique solution. Use two models of randomness: (i) Each
matrix whose elements are permutations of the multiset {8 x 0, 8 x 1, . . . , 8 x 6} is equally
likely; (ii) each matrix obtained from a random shuffle of the dominoes is equally likely.
73. [46] What’s the maximum number of solutions to an instance of Dominosa?
July 26, 2019
68 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
74. [22] (M. Keller, 1987.) Is there a uniquely solvable Dominosa array for which Keller
every domino matches two adjacent cells of the array in either three or four places? grope
binary operation
► 75. [M24 ] A grope is a set G together with a binary operation ◦, in which the identity multiplication tables
idempotent
x ◦ (y ◦ x) = y is satisfied for all x € G and y € G. commutative
a) Prove that the identity (x ◦ y) ◦ x = y also holds, in every grope. identity element
subgraph
b) Which of the following “multiplication tables” define a grope on {0, 1, 2, 3}? word search puzzle
0123 0321 0132 0231 0312
1032 3210 1023 3102 2130
2301 ; 2103; 3210; 1320; 3021
3210 1032 2301 2013 1203
(In the first example, x ◦ y = x ф y; in the second, x ◦ y = (—x — y) mod 4. The
last two have x ◦ y = x ф f (x ф y) for certain functions f.)
c) For all n, construct a grope whose elements are {0, 1, . . . , n — 1}.
d) Consider the exact cover problem that has n2 items xy for 0 < x,y < n and the
following n + (n3 — n)/3 options:
i) ‘xx’, for 0 < x < n;
ii) ‘xx xy yx’, for 0 < x < y < n;
iii) ‘xy yz zx’, for 0 < x < y, z < n.
Show that its solutions are in one-to-one correspondence with the multiplication
tables of gropes on the elements {0, 1, . . . , n — 1}.
e) Element x of a grope is idempotent if x ◦ x = x. If k elements are idempotent and
n — k are not, prove that k = n2 (modulo 3).
76. [21] Modify the exact cover problem of exercise 75(d) in order to find the mul
tiplication tables of (a) all idempotent gropes — gropes such that x ◦ x = x for all x;
(b) all commutative gropes — gropes such that x ◦ y = y ◦ x for all x and y; (c) all
gropes with an identity element — gropes such that x ◦ 0 = 0 ◦ x = x for all x.
77. [M21 ] Given graphs G and H , each with n vertices, use Algorithm X to decide
whether or not G is isomorphic to a subgraph of H .
78. [16] Show that it’s quite easy to pack the 27 mathematicians’ names of Fig. 71
into a 12 x 15 array, with all names reading correctly from left to right. (Of course that
would be a terrible word search puzzle.)
79. [M20] How many options are in (48), when they are completely listed?
80. [19] Play through Algorithm C by hand, using exercise 9 in step C3 and the input
in Table 2, until first reaching a solution. What are the contents of memory then?
81. [21] True or false: An exact cover problem that has no color assignments has
exactly the same running time on Algorithms X and C.
82. [21 ] True or false: It’s possible to save memory references in Algorithms X and C
by not updating the len fields in the hide/unhide operations when x > N1.
► 83. [20] Algorithm C can be extended in the following curious way: Let p be the
primary item that is covered first, and suppose that there are k ways to cover it.
Suppose further that the jth option for p ends with a secondary item sj , where
{s1 , . . . , sk} are distinct. Modify the algorithm so that, whenever a solution contains
the jth option for p, it leaves items {s1 , . . . , sj-1 } uncovered. (In other words, the
modified algorithm will emulate the behavior of the unmodified algorithm on a much
larger instance, in which the jth option for p contains all of s1 , s2, . . . , sj.)
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—FIRST SET 69
► 84. [25] Number the options of an XCC problem from 1 to M. A minimax solution minimax solution
is one whose maximum option number is as small as possible. Explain how to modify bottleneck optimum, see minimax
modify Algorithm C
Algorithm C so that it determines all of the minimax solutions (omitting any that are Monte Carlo estimate
known to be worse than a solution already found). estimated time
double word square
85. [22] Sharpen the algorithm of exercise 84 so that it produces exactly one minimax word square, double
solution — unless, of course, there are no solutions at all. OSPD4
word stair
► 86. [M25] Modify Algorithm C so that, instead of finding all solutions to a given
XCC problem, it gives a Monte Carlo estimate of the number of solutions and the
time needed to find them, using Theorem 7.2.2E. (Thus the modified algorithm is to
Algorithm C as Algorithm 7.2.2E is to Algorithm 7.2.2B.)
87. [20] A double word square is an n x n array whose rows and columns contain 2n
different words. Encode this problem as an XCC problem. Can you save a factor of 2 by
not generating the transpose of previous solutions? Does Algorithm C compete with the
algorithm of exercise 7.2.2-28 (which was designed explicitly to handle such problems)?
88. [21 ] Instead of finding all of the double word squares, we usually are more inter
ested in finding the best one, in the sense of using only words that are quite common.
For example, it turns out that a double word square can be made from the words of
words(1720) but not from those of words(1719). Show that it’s rather easy to find the
smallest W such that words(W) supports a double word square, via dancing links.
89. [24 ] What are the best double word squares of sizes 2 x 2, 3 x 3, . . . , 7 x 7, in
the sense of exercise 88, with respect to The Official SCRABBLE'- Players Dictionary?
[Exercise 7.2.2-32 considered the analogous problem for symmetric word squares.]
► 90. [22] A word stair of period p is a cyclic arrangement of words, offset stepwise, that
contains 2p distinct words across and down. They exist in two varieties, left and right:
STAIR STAIR
SHARP SLOOP
STEMS STOOD
SCRAP STEER
STAIR STAIR
SHARP SLOOP
stems p=4 STOOD
SCRAP STEER
STAIR STAIR
What are the best five-letter word stairs, in the sense of exercise 88, for 1 < p < 10?
Hint: You can save a factor of 2p by assuming that the first word is the most common.
91. [40] For given W, find the largest p such that words(W) supports a word stair of
period p. (There are two questions for each W, examining stairs to the {left, right}.)
92. [24] Some p-word cycles define two-way word stairs that have 3p distinct words:
RAP ID RAPID
RATED RATED
LACES LACES
ROBES ROBES
RAPID RAPID
RATED RATED
laces p=4 LACES
ROBES ROBES
RAPID RAP ID
What are the best five-letter examples of this variety, for 1 < p < 10?
July 26, 2019
70 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
(0000000100000110000101000101100010010101001001100100011010000111)
exhibits all binary 7-tuples with a majority of 0s. When n = 7, p = 3, q = 4, the cycle
(0000111000101100011010010101011010100110011011001011100100111010001111)
shows all 7-tuples obtainable by removing the first bit of an 8-tuple with four 0s, four 1s.
Exactly how many cycles exist, when (n, p, q) = (7, 0, 3) or (7, 3, 4)? How long
does it take for Algorithm C to find them?
96. [M20] Find an 8 x 8 binary torus whose sixty-four 2 x 3 subrectangles are distinct.
97. [M21 ] Find all 9 x 9 ternary ourotoruses D = (di,j) that are symmetrical, in the
sense that d(i+3) mod 9,(j+3) mod 9 = (di,j + 1) mod 3. (See exercise 7.2.1.1-109.)
98. [25] Prove that the exact cover problem with color controls is NP-complete, even
if every option consists of only two items.
99. [20] True or false: Every XCC problem can be reformulated as an ordinary exact
cover problem with the same solutions and the same number of options.
► 100. [20] The general constraint satisfaction problem (CSP) is the task of finding all
n-tuples x1 . . . xn that satisfy a given system of constraints C1, . . . , Cm , where each
constraint is defined by a relation on a nonempty subset of the variables {x1 , . . . , xn}.
For example, a unary constraint is a relation of the form xk G Dk; a binary
constraint is a relation of the form (xj, xk) G Djk; a ternary constraint is a relation of
the form (xi , xj , xk) G Dijk ; and so on.
a) Find all x1x2x3x4x5 for which 0 < x1 < x2 < x3 < x4 < x5 < 2 and x1 +x3 +x5 = 3.
b) Formulate the problem of part (a) as an XCC problem.
c) Explain how to formulate any CSP as an XCC problem.
► 101. [25] (The zebra puzzle.) Formulate the following query as an XCC problem: “Five
people, from five different countries, have five different occupations, own five different
pets, drink five different beverages, and live in a row of five differently colored houses.
• The Englishman lives in a red house. • The painter comes from Japan.
• The yellow house hosts a diplomat. • The coffee-lover’s house is green.
• The Norwegian’s house is the leftmost. • The dog’s owner is from Spain.
• The milk drinker lives in the middle house. • The violinist drinks orange juice.
July 26, 2019
7.2.2.1 dancing links: exercises—first set 71
• The white house is just left of the green one. • The Ukrainian drinks tea. Japanese arrow puzzle
• The Norwegian lives next to the blue house. • The sculptor breeds snails. Music
equal temperament
• The horse lives next to the diplomat. • The nurse lives next to the fox. pitch class
Who trains the zebra, and who prefers to drink just plain water?” Schoenberg
twelve-tone row
► 102. [25] Explain how to find all solutions to a Japanese arrow puzzle with Algo permutation
rithm C. (See exercise 7.2.2-68.) Berg
n-tone row
► 103. [M28] Musical pitches in the Western system of “equal temperament” are the all-interval
reversal
notes whose frequency is 440 • 2n/12 cycles per second, for some integer n. The pitch perfect
class of such a note is n mod 12, and seven of the twelve possible pitch classes are
conventionally designated by letters:
0 = A, 2 = B, 3 = C, 5 = D, 7 = E, 8 = F, 10 = G.
The other classes are named by appending sharp (J) or flat (b) signs, to go up or down
by 1; thus 1 = A# = Bb, 4 = CJ = Db, ..., 11 = GJ = Ab.
Arnold Schoenberg popularized a composition technique that he called a twelve-
tone row, which is simply a permutation of the twelve pitch classes. For example, his
student Alban Berg featured the motif
105. [22 ] Using the “word search puzzle” conventions of Figs. 71 and 72, show that word search puzzle
the words one, two, three, four, five, six, seven, eight, nine, ten, eleven, and word search
sudoku
TWELVE can all be packed into a 6 x 6 square, leaving one cell untouched. presidents
I’m not sure
106. [22] Also pack two copies of ONE, TWO, THREE, FOUR, FIVE into a 5 x 5 square. how many of
these names
► 107. [25] Pack as many of the following words as possible into a 9 x 9 array, simul should go in
taneously satisfying the rules of both word search and sudoku: the index
connected
ACRE COMPARE CORPORATE MACRO MOTET ROAM wordcross
ART COMPUTER CROP META PARAMETER TAME crisscross puzzle, composing, see wordcross
rookwise connected
components
► 108. [32] The first 44 presidents of the U.S.A. had 38 distinct surnames: ADAMS, crossword puzzle diagrams
arthur, buchanan, bush, carter, cleveland, clinton, coolidge, eisenhower, fill 5-letter words
more, ford, garfield, grant, harding, harrison, hayes, hoover, jackson, jefferson, Torto
noncrossing king path
johnson, kennedy, lincoln, madison, mckinley, monroe, nixon, obama, pierce, polk, king path
reagan, roosevelt, taft, taylor, truman, tyler, vanburen, washington, wilson. English words
alphabet block
a) What’s the smallest square into which all of these names can be packed, using
word search conventions, and requiring all words to be connected via overlaps?
b) What’s the smallest rectangle, under the same conditions?
► 109. [28] A “wordcross puzzle” is the challenge of packing a given set of words into
a rectangle under the following conditions: (i) All words must read either across or
down, as in a crossword puzzle. (ii) No letters are adjacent unless they THREE F
b elong to one of the given words. (iii) The words are rookwise connected. W SIX
ONE V
(iv) Words overlap only when one is vertical and the other is horizontal. SEVEN
For example, the eleven words zero, one, . . . , ten can be placed into an ZI
EIGHT N
8 x 8 square under constraints (i) and (ii) as shown; but (iii) is violated, R EE
because there are three different components. FOUR N
Explain how to encode a wordcross puzzle as an XCC problem. Use your encoding
to find a correct solution to the problem above. Do those eleven words fit into a smal ler
rectangle, under conditions (i), (ii), and (iii)?
110. [30] What’s the smallest wordcross square that contains the surnames of the first
44 U.S. presidents? (Use the names in exercise 108, but change vanburen to van buren.)
111. [21 ] Find all 8 x 8 crossword puzzle diagrams that contain exactly (a) 12 3-letter
words, 12 4-letter words, and 4 5-letter words; (b) 12 5-letter words, 8 2-letter words,
and 4 8-letter words. They should have no words of other lengths.
► 112. [28] A popular word puzzle in Brazil, called ‘Torto’ (‘bent’), asks solvers OCG
to find as many words as possible that can be traced by a noncrossing king path FMN
MIP
in a given 6 x 3 array of letters. For example, each of the words the, mature, AUR
art, of, computer, and programming can be found in the array shown here. TRO
EHG
a) Does that array contain other common words of eight or more letters?
b) Create a 6 x 3 array that contains torto, words, solver, and many other inter
esting English words of five or more letters. (Let your imagination fly.)
c) Is it possible to pack one, two, three, . . . , eight, nine, ten into a Torto array?
► 113. [21 ] An ‘alphabet block’ is a cube whose six faces are marked with letters. Is
there a set of five alphabet blocks that are able to spell the 25 words trees, nodes,
stack, avail, first, right, order, lists, given, links, queue, graph, times, block,
value, table, field, empty, above, point, three, until, hence, quite, deque? (Each
of these words appears more than 50 times in Chapter 2.)
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—FIRST SET 73
114. [M25] Let a be a permutation of the cells of a 9 x 9 array that takes any sudoku permutation
solution into another sudoku solution. We say that a is an automorphism of the sudoku sudoku solution
automorphism
solution S = (sij) if there’s a permutation n of {1, 2,. .. , 9} such that S(ij)a = sijn for transposition
0 < i, j < 9. For example, the permutation that takes ij into (ij)a = ji, commonly automorphism
hypersudoku
called transposition, is an automorphism of (28b), with respect to the permutation Mycielski graphs
n = (24)(37)(68); but it is not an automorphism of (28a) or (28c). triangle-free
Show that Algorithm C can be used to find all sudoku solutions that have a given chromatic number
x-critical
automorphism a, by defining an appropriate XCC problem. Graph coloring
How many sudoku solutions have transposition as an automorphism? cliques
queen graph
115. [M25] Continuing exercise 114, how many hypersudoku solutions have auto symmetry-breaking
morphisms of the following types? (a) transposition; (b) the transformation of ex Mycielski graph
Hypergraph coloring
ercise 67(d); (c) 90° rotation; (d) both (b) and (c). no-three-in-line problem
► 116. [M25] Given a graph on vertices V, let ^(G) be the graph obtained by (i) adding Factorize
new vertices V' = {v' | v G V}, with u' — v when u — v; and also (ii) adding another
vertex w, with w — v' for all v' G V'. (If G has m edgesand n vertices, ^(G) has 3m+n
edges and 2n +1 vertices.) The Mycielski graphs Mc are defined for all c > 2 by setting
M2 = K2 and Mc+1 = M(Mc); they have 17g3c — 42c + 11 edges and 42c — 1 vertices:
M2 = 0—0; M3 = <>; M4 =
120. [M29] Section 2.3.4.3 discussed Hao Wang’s “tetrad tiles,” which are squares Wang
that have specified colors on each side. Find all ways in which the entire plane can be tetrad tiles
toroidal
filled with tiles from the following families of tetrad types, always matching colors at the infinity lemma
edges where adjacent tiles meet [see Scientific American 231, 5 (Nov. 1965), 103, 106]: symmetric
mappings
a) partitions of a set
Stirling subset numbers
unlabeled
b) coordinates
triangles, coordinates for
triangles
(The tetrad tiles must not be rotated or flipped.) Hint: Algorithm C will help. MacMahon’s triangles
► 121. [M29] Exercise 2.3.4.3-5 discusses 92 types of tetrads that are able to tile the symmetries
strong symmetry
plane, and proves that no such tiling is toroidal (periodic).
a) Show that the tile called eUS in that exercise can’t be part of any infinite tiling.
In fact, it can appear in only n + 1 cells of an m x n array, when m,n > 4.
b) Show that, for all k > 1, there’s a unique (2k — 1) x (2k —1) tiling for which the
middle tile is 3RD. (Consequently, by the infinity lemma, there’s a unique tiling
of the entire plane in which 3RD is placed at the origin.)
c) Similarly, show that there are exactly (2, 3, 3, 57) tilings of size (2k—1) x (2k—1)
whose middle tile is respectively (3RU, 3LD, 3LU, 3SU), for all k > 3.
d) How many tilings of the infinite plane have (3RU, 3LD, 3LU, 3SU) at the origin?
► 122. [28] Extend Algorithm C so that it finds only 1/d! of the solutions, in cases
where the input options are totally symmetric with respect to d of the color values,
and where every solution contains each of those color values at least once. Assume that
those values are {v, v+ 1, . . . , v+d— 1}, and that all other colors have values < v. Hint:
Modify the algorithm so that the first such color it assigns is always v, then v + 1, etc.
123. [M20] Apply the algorithm of exercise 122 to the following toy problem with
parameters m and n: There are n primary items pk and n secondary items qk, for 1 <
k < n; and there are mn options, ‘pk qk:j’ for 1 < j < m and 1 < k < n. (The solutions
to this problem are the mappings of {1, . . . , n} into {1, . . . , m}, which may also be
regarded as the partitions of {1,.. . ,n} into m parts labeled {1,... , m}.) Algorithm C
will obviously find mn = {n}m- + ["}m2 + • • • n^}mm solutions. But the modified
algorithm finds only the “unlabeled” partitions, of which there are {n} + {n }+• • •+{nn}.
► 124. [M22] Devise a system of coordinates for representing the positions of equilateral
triangles in patterns such as (59). Represent also the edges between them.
125. [M20] When a set of s triangles is magnified by an integer k , we obtain sk2
triangles. Describe the coordinates of those triangles, in term of the coordinates of the
originals, using the system of exercise 124.
126. [23] Find all solutions of MacMahon’s problem (59), by applying Algorithm C
to a suitable set of items and options based on the coordinate system in exercise 124.
How much time is saved by using the improved algorithm of exercise 122?
127. [M28] There are 4-2 ways to prescribe the border colors of a hexagon like those in
(59). Which of them can be completed to a color-matched placement of all 24 triangles?
► 128. [25] Eleven of MacMahon’s triangles (58) involve only the first three colors (not
black). Arrange them into a pleasant pattern that tiles the entire plane when replicated.
► 129. [M34 ] The most beautiful patterns that can be made with MacMahon’s triangles
are those with attractive symmetries, which can be of two kinds: strong symmetry (a
rotation or reflection that doesn’t change the pattern, except for permutation of colors)
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—FIRST SET 75
or weak symmetry (a rotation or reflection that preserves the “color patches,” the set weak symmetry
of boundaries between different colors). color patches
octahedron
MacMahon
jigsaw puzzle
triple three triominoes
strong symmetry: weak symmetry: triominoes
Philpott
equilateral triangle
MacMahon
polyominoes
Exactly how many essentially different symmetrical patterns are possible, in a hexagon? pentomino
Nelson
130. [21 ] Partition MacMahon’s triangles (58) into three sets of eight, each of wrap around
which can be placed on the faces of an octahedron, with matching edge colors. cube
Conway
131. [28] (P. A. MacMahon, 1921.) Instead of using the colored tiles of (58), which pentagon
yield (59), we can form hexagons from 24 different triangles in two other ways: dodecahedron
The left diagram shows a “jigsaw puzzle” whose pieces have four kinds of edges. The
right diagram shows “triple three triominoes,” which have zero, one, two, or three spots
at each edge; adjacent triominoes should have a total of three spots where they meet.
a) In how many ways can that jigsaw puzzle make a hexagon? (All pieces are white.)
b) How many triomino arrangements have that pattern of dots at the edges?
132. [40] (W. E. Philpott, 1971.) There are 4624 = 682 tiles in a set that’s like (58),
but it uses 24 different colors instead of 4. Can they be assembled into an equilateral
triangle of size 68, with constant color on the boundary and with matching edges inside?
133. [21] (P. A. MacMahon, 1921.) A set of 24 square tiles can be con
structed, analogous to the triangular tiles of (58), if we restrict ourselves
to just three colors. For example, they can be arranged in a 4x 6 rectangle
as shown, with all-white border. In how many ways can this be done?
134. [23] The nonwhite areas of the pattern in exercise 133 form polyominoes (rotated
45°); in fact, the lighter color has an S pentomino, while the darker color has both P
and V. How often do each of the twelve pentominoes occur, among all of the solutions?
135. [23] (H. L. Nelson, 1970.) Show that MacMahon’s squares of exercise 133 can be
used to wrap around the faces of a 2 x 2 x 2 cube, matching colors wherever adjacent.
► 136. [HM28] (J. H. Conway, 1958.) There are twelve ways to label the edges of a pen
tagon with {0, 1, 2, 3, 4}, if we don’t consider rotations and reflections to be different:
Cover a dodecahedron with these tiles, matching edge numbers. (Reflections are OK.)
July 26, 2019
76 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
137. [22 ] A popular puzzle called Drive Ya Nuts consists of seven Drive Ya Nuts
“hex nuts” that have been decorated with permutations of the num cyclic permutations
puzzle design
bers {1, 2, 3, 4, 5, 6}. The object is to arrange them as shown, with Heads and tails
numbers matching at the edges. MacMahon
permutations
a) Show that this puzzle has a unique solution, with that partic flipped over
ular set of seven. (Reflections of the nuts are not OK!) tile the plane
b) Can those seven nuts form the same shape, but with the label torus
symmetries
numbers summing to 7 where they meet ({1, 6}, {2, 5}, or {3,4}) wallpaper
c) Hex nuts can be decorated with {1, 2, 3, 4, 5, 6} in 5! = 120 different ways. If Langford
MacMahon
seven of them are chosen at random, what’s the approximate probability that
vertex matching
they define a puzzle with a unique solution, under matching condition (a)?
d) Find seven hex nuts that have a unique solution under both conditions (a) and (b).
138. [25] (Heads and tails.) Here’s a set of 24 square tiles that MacMahon missed(!):
They each show two “heads” and two “tails” of triangles, in four colors that exhibit all
possible permutations, with heads pointing to tails. The tiles can be rotated, but not
flipped over. We can match them properly in many ways, such as
where the 4 x 6 arrangement will tile the plane; the 5 x 5 arrangement has a special
“joker” tile in the middle, containing all four heads.
a) How many 4 x 6 arrangements will tile the plane? (Consider symmetries.)
b) Notice that the half-objects at the top, bottom, left, and right of the 5 x 5 arrange
ment match the heads in the middle. How many such arrangements are possible?
c) Devise a 5 x 5 arrangement that will tile the plane, in conjunction with the 5 x 5
pattern shown above. Hint: Use an “anti-joker” tile, which contains all four tails.
139. [M25] Excellent human-scale puzzles have been made by choosing nine of the
24 tiles in exercise 138, redrawing them with whimsical illustrations in place of the
triangles, and asking for a 3 x 3 arrangement in which heads properly match tails.
a) How many of the 294 choices of 9 tiles lead to essentially different puzzles?
b) How many of those puzzles have exactly k solutions, for k = 0, 1, 2, . . . ?
140. [29] (C. D. Langford, 1959.) MacMahon colored the edges of his tiles, but we
can color the vertices instead. For example, we can make two parallelograms, or a
July 26, 2019
7.2.2.1 dancing links: exercises—first set 77
a) In how many essentially different ways can those 24 tiles be properly packed into
rectangles of these sizes, leaving a hole in the middle of the 5 x 5?
b) Discuss tiling the plane with such solutions.
► 142. [23] (Zdravko Zivkovic, 2008.) Edge and vertex matching can be combined into
a single design if we replace MacMahon’s 24 squares by 24 octagons. For example,
illustrate 4 x 6 arrangements in which there’s vertex matching in the (i) left half,
(ii) bottom half, or (iii) northwest and southeast quadrants, while edge matching occurs
elsewhere. (We get vertex matching when an octagon’s center is ‘O’, edge matching
when it’s ‘П’.) How many 4 x 6 arrangements satisfy (i), (ii), and (iii), respectively?
► 143. [M25] The graph simplex(n, a, b, c, 0, 0, 0) in the Stanford GraphBase is the trun
cated triangular grid consisting of all vertices xyz such that
x + y + z = n, 0 < x < a, 0 < y < b, and 0 < z < c.
Two vertices are adjacent if their coordinates all differ by at
most 1. The boundary edges always define a convex polygon.
For example, simplex (7, 7, 5, 3, 0, 0, 0) is illustrated here.
a) What simplex graphs correspond to the three shapes in exercise 140?
July 26, 2019
78 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
b) The examples in (a) have 24 interior triangles, but simplex (7, 7, 5, 3, 0, 0, 0) has 29. hexagons
Can any other convex polygons be made from 24 triangles, connected edgewise? cuboid
coordinates
c) Design an efficient algorithm that lists all possible convex polygons that can be cube, coordinates for
formed from exactly N triangles, given N. Hint: Every convex polygon in a cube
Instant Insanity
triangular grid can be characterized by the six numbers in its boundary path
Х0Х1Х2Х3Х4Х5, which moves xk steps in direction (60k)° for k = 0, 1, ... ,5. For
example, the boundary of simplex (7, 7, 5, 3, 0, 0, 0) is 503412.
d) Can every convex polygon in a triangular grid be described by a simplex graph?
144. [24] The idea of exercise 142 applies also to triangles and hexagons, allowing us
to do both vertex and edge matching with yet another set of 24 tiles:
(i) (ii)
Here there’s vertex matching in the bottom five tiles of (i), and in the upper left five
and bottom five of (ii), with edge matching elsewhere. In how many ways can the big
hexagon be made from these 24 little hexagons, under constraints (i) and (ii)?
► 145. [M20] Many problems that involve an l x m x n cuboid require a good internal
representation of its (l+1)(m+1)(n+1) vertices, its l(m+1)(n+1) + (l+1)m(n+1) +
(l+1)(m+1)n edges, and its lm(n+1) +l(m+1)n+ (l+1)mn faces, in addition to its lmn
individual cells. Show that there’s a convenient way to do this with integer coordinates
(x,y,z) whose ranges are 0 < x < 2l, 0 < y < 2m, 0 < z < 2n.
► 146. [M30] There are 30 ways to paint the colors {a, b, c, d, e, f} on the faces of a cube:
aaaaa aaaaa
e^k-f f^kde ^k-b ^k-f ^kfc c Jfb cJ^d d^kbc ^kce e^kcd
c c d d e e f f b b
bbccd deeff
aaaaaaaaaa
eeffbbccdd
f^K-d d^K-f b^^e e^^b c^^f f^F-c d^F-b b^^d e^^c c^^e
ccddeeffbb
bbccddeeff
aaaaaaaaaa
ffbbccddee
d—y^-—e e—y^~—d e—y^~—f f—y^~—e f—y^~—b b—y^~—f b—y^~—c c—y^~—b c—y^~—d d—y^~—c
ccddeeffbb
bbccddeeff
(If a is on top, there are five choices for the bottom color, then six cyclic permutations
of the remaining four.) Here’s one way to arrange six differently painted cubes in a row,
with distinct colors on top, bottom, front, and back (as in “Instant Insanity”), and with
the further proviso that adjacent cubes have matching colors where they share a face:
abcdef
f a b c d e
^^d ^^e ^^f ^^a a^f^b ^^c
b c d e f a (*)
efabcd
a) Explain why any such arrangement also has the same color at the left and right.
July 26, 2019
7.2.2.1 dancing links: exercises—first set 79
b) Invent a way to name each cube, distinguishing it from the other 29. bricks
c) How many essentially different arrangements like (*) are possible? Vertex-colored tetrahedra
simplex
d) Can all 30 cubes be used to make five such arrangements simultaneously? tetrahedron
Endless Chain
147. [30] The 30 cubes of exercise 146 can be used to make “bricks” Path dominoes
of various sizes l x m x n, by assembling l • m • n of them into a cuboid central symmetry
that has solid colors on each exterior face, as well as matching colors Hamiltonian cycle
loop
on each interior face. For example, each cube naturally joins with its
mirror image to form a 1 x 1 x 2 brick. Two such bricks can then join
up to make a 1 x 2 x 2; the one illustrated here has a in front, b in
the back, c at the left and right, d at the top, and e at the bottom.
a) Assemble all 30 cubes into a magnificent brick of size 2 x 3 x 5.
b) Compile a catalog of all the essentially different bricks that can be made.
148. [24 ] Find all the distinct cubes whose faces are colored a, b, or c, when opposite
faces are required to have different colors. Then arrange them into a symmetric shape
(with matching colors wherever they are in contact).
149. [M22] (Vertex-colored tetrahedra.) The graph simplex (3, 3, 3, 3, 3, 0, 0) is a tetra
hedron of side 3 with 20 vertices. It has 60 edges, which come from 10 unit tetrahedra.
There are ten ways to color the vertices of a unit tetrahedron with four of the five
colors {a, b, c, d, e}, because mirror reflections are distinct. Can those ten colored tetra-
hedra be packed into simplex (3, 3, 3, 3, 3, 0, 0), with matching colors at every vertex?
150. [23] Here’s a classic 19th century puzzle that was the first of its kind: “Arrange
all the pieces to fill the square . . . so that all the links of the Chain join together,
forming an Endless Chain. The Chain may be any shape, so long as all the links join
together, and all the pieces are used. This Puzzle can be done several different ways.”
(The desired square is 8 x 8.) In exactly how many different ways can it be solved?
► 151. [30] (Path dominoes.) A domino has six natural attachment points on its bound
ary, where we could draw part of a path that connects to neighboring dominoes. Thus
a) Only two of the dominoes in the arrangement above are in horizontal position.
Find a single-loop 8 x 9 arrangement that has 18 horizontals and 18 verticals.
b) Similarly, find an arrangement that has the maximum number of horizontals.
152. [30] The complete set of path dominoes includes also twelve more patterns:
153. [25 ] Here are six of the path dominoes, plus a “start” piece and a “stop” piece: Singleton
partridge puzzle
Diophantine equations
affinity score
+ backtracking
bitwise techniques
5-queens problem
a) Place them within a 4 x 5 array so that they define a path from “start” to “stop.” symmetries of a square
b) How many distinct “start” or “stop” pieces are possible, if they’re each supposed components
giant
to contain a single subpath together with a single terminal point? queen-domination problems
c) Design an eight-piece puzzle that’s like (a), but it involves four of the two-subpath clique dominators
dominoes instead of only two. (Your puzzle should have a unique solution.) MCC problem
154. [M30] (C. R. J. Singleton, 1996.) After twelve days of Christmas, the person
who sings a popular carol has received twelve partridges in pear trees, plus eleven pairs
of humming birds, . . . , plus one set of twelve drummers drumming, from his or her true
love. Therefore an “authentic” partridge puzzle should try to pack (n+ 1 - k) squares of
size k x k, for 1 < k < n, into a box that contains P (n) = n • 12 + (n — 1) • 22 + • • • + 1 • n2
cells. For which values of n is P(n) a perfect square?
155. [20 ] That “authentic” partridge puzzle has a square solution when n = 6.
a) Exactly how many different solutions does it have in that case?
b) The affinity score of a partridge packing is the number of internal edges that lie
on the boundary between two squares of the same size. (In (62) the scores are 165
and 67.) What solutions to (a) have the maximum and minimum affinity scores?
► 156. [30] Straightforward backtracking will solve the partridge puzzle for n = 8, using
bitwise techniques to represent a partially filled 36 x 36 square in just 36 octabytes,
instead of by treating it as the huge MCC problem (61) and applying a highly gen
eral solver such as Algorithm M. Compare these two approaches, by implementing
them both. How many essentially different solutions does that partridge puzzle have?
157. [22] Complete the study of small partridges by extending (63) to n = 6 and 7.
158. [23] Another variation of the partridge puzzle when 2 < n < 7 asks for the
smallest rectangular area that will contain k nonoverlapping squares of size k x k for
1 < k < n. For example, here are solutions for n = 2, 3, and 4:
(To show optimality for n = 4 one must prove that rectangles of sizes 6 x 17, 8 x 13,
5 x 21, and 7 x 15 are too small.) Solve this puzzle for n = 5, 6, and 7.
► 159. [21 ] Suggest a way to speed up the text’s solution to the 5-queens problem, by
using the symmetries of a square to modify the items and options of (64).
160. [21 ] The 5-queens problem leads to an interesting graph, whose vertices are the
4860 solutions, with u ——— v when we can get from u to v by moving one queen. How
many connected components does this graph have? Is one of them a “giant”?
► 161. [23] Three restricted queen-domination problems are prominent in the literature:
i)No two queens of a solution attack each other.
ii)Each queen of a solution is attacked by at least one of the others.
iii)The queens of a solution form a clique.
(The third and fourth examples in (65) are instances of types (ii) and (i).)
Explain how to formulate each of these variants as an MCC problem, analogous
to (64). How many solutions of each type are present in the 5-queens problem?
July 26, 2019
queens
n queens problem
LEN
SLACK
BOUND
MCC problem
identical options
independent sets
MCC problem
kernels
Petersen graph
5-letter words
164. [17] When Algorithm M finds a solution x0x1 . . . xl-1 in step M2, some of the snake-in-the-box path
nodes xj might represent the fact that some primary item will appear in no further induced graph
connected
options. Explain how to handle this “null” case, by modifying answer 13. strong product x
165. [M30] Consider an MCC problem in which we must choose 2 of 4 options to cover king moves
chessboard
item 1, and 5 of 7 options to cover item 2; the options don’t interact. knight moves
a) What’s the size of the search tree if we branch first on item 1, then on item 2? bishop moves
Would it better to branch first on item 2, then on item 1? rook moves
queen moves
b) Generalize part (a) to the case when item 1 needs p of p+ d options, while item 2
needs q of q + d options, where q > p and d > 0.
166. [21 ] Extend answer 9 to the more general situation that arises in Algorithm M:
a) Let Op be the number of different choices that will be explored at the current
position of the search tree if primary item p is selected for branching. Express Op
as a function of len(p), slack(p), and bound(p).
b) Suppose Op = Op, and SLACK(p) = SLACK(p') = 0, but LEN(p) < LEN(p'). Should
we prefer to branch on p or on p, based on exercise 165?
167. [24] Let Mp be the number of options that involve the primary item p in a given
MCC problem, and suppose that the upper bound vp for p’s multiplicity is > Mp. Does
the precise value of this upper bound affect the behavior of Algorithm M? (In other
words, does vp = to lead to the same running time as vp = Mp?)
► 168. [15] An MCC problem might have two identical options a, whose items are
allowed to occur more than once. In such cases we might want the second copy of a to
be in the solution only if the first copy is also present. How can that be achieved?
► 169. [22] Let G be a graph with n vertices. Formulate the problem of finding all of
its t-element independent sets as an MCC problem with 1 + n items and n options.
170. [22] Continuing exercise 169, generate all of G’s t-element kernels —its maximal
independent sets. (Your formulation will now need additional items and options.)
171. [25] Label the vertices of the Petersen graph with ten 5-letter words, in such a
way that vertices are adjacent if and only if their labels have a common letter.
► 172. [29] A snake-in-the-box path in a graph G is a set U of vertices for which the
induced graph G | U is a path. (Thus there are start/stop vertices s G U and t G U that
each have exactly one neighbor in U; every other vertex of U has exactly two neighbors
in U; and G | U is connected.)
For example, let G = P4 и P4 be the graph of king moves on a 4 x 4
board. The set of kings illustrated at the right is not a snake-in-the-box
path in G; but it becomes one if we remove the king in the corner.
a) Use Algorithm M to discover all of the longest snake-in-the-box paths that are
possible on an 8 x 8 chessboard, when G is the graph of all (i) king moves;
(ii) knight moves; (iii) bishop moves; (iv) rook moves; (v) queen moves.
July 26, 2019
82 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
b) Similarly, a snake-in-the-box cycle is a set for which G | U is a cycle. (In other snake-in-the-b ox cycle
words, that induced graph is connected and 2-regular.) What are the longest 2-regular
Knight and bishop sudoku
possible snake-in-the-box cycles for those five chess pieces? pi, as source
Beluhov
► 173. [30] (Knight and bishop sudoku.) Diagram (i) shows 27 knights, arranged with 01 mtx
three in each row, three in each column, and three in each 3 x 3 box. Each of them has MCC problem
been labeled with the number of others that are a knight’s move away. Diagram (ii) repeated options
012 mtx
shows 9 of them, from which the positions of the other 18 can be deduced. Diagrams MCC problems
(iii) and (iv) are analogous, but for bishops instead of knights: (iii) solves puzzle (iv). repeated items
d) Construct a uniquely solvable knight sudoku puzzle that has only three clues.
174. [35] (Nikolai Beluhov, 2019.) Find a uniquely solvable sudoku puzzle with nine
labeled knights that remains uniquely solvable when the knights are changed to bishops.
► 175. [M21 ] Given an M x N matrix A = (aij) of 0s and 1s, explain how to find all
vectors x = (x1... xM) with 0 < xi < ai for 1 < i < M such that xA = (y1 ... yN),
where uj < yj < vj for 1 < j < N. (This generalizes the MCC problem by allowing the
ith option to be repeated up to ai times.)
► 176. [M25] Given an M x N matrix A = (aij) of 0s, 1s, and 2s, explain how to find
all subsets of its rows that sum to exactly (a) 2 (b) 3 (c) 4 (d) 11 in each column, by
formulating those tasks as MCC problems.
177. [M21] Algorithm 7.2.1.5M generates the p(n1 , . . . , nm) partitions of the multiset
{n1 • x1,... ,nm • xm} into submultisets. Use the previous two exercises to generate
these partitions with Algorithm M, in the cases where n1 = • • • = ns = 1 and ns+1 =
• • • = ns+t = 2 and s + t = m. Also generate the q(n1, . . . , nm) multipartitions into
distinct multisets.
178. [M22] (Factorizations of an integer.) Use Algorithm M to find all representations
of 360 as a product n1 • n2 • . . . • nt, where (a) 1 < n1 < • • • < nt; (b) 2 < n1 < • • • < nt.
July 26, 2019
7.2.2.1 dancing links: exercises—first set 83
179. [15] By removing duplicate rows and columns, matrix A reduces to A': Eppstein
strict exact cover problem
100000 Eppstein
011100 1000 strict exact cover problem
110111 0110 extreme problem
exponential generating function
0 1110 0 1101 Gould numbers
A= 0 0 0 0 1 1 ; A' = 0001 Peirce’s triangle
0 0 0 0 1 1 1010
10 10 0 0 0101
010111 1110
111100
Derive the exact covers of A from the exact covers of A.
► 180. [M28] (D. Eppstein, 2008.) Prove that every strict exact cover problem with
parameters 1 < t' < t, as defined in (74), contains t' items i1, ... , it/ and t+t—1 options
op = ‘i1 ... ip’, for 1 < p < t'; op+q = ‘ ... it' ... ’, for 1 < q <t.
Furthermore, ir G op+q if and only if 1 < q < t — r — t', for 1 < r < t'.
181. [M20] Find constants cr such that D(5n + r) = 4ncr — 3 for n > 3 and 0 < r < 5.
182. [21 ] (D. Eppstein, 2008.) Find a strict exact cover problem with 8 options,whose
search tree contains 16 nodes and 7 solutions.
183. [46] Let D(n) be the maximum number of nodes in Algorithm X’s search tree,
taken over all strict exact cover problems with n options. What is lim siipn . D(n)1/n?
► 184. [M22] Suppose 0 < t < wn. Is there a strict exact cover problem with n items
that has exactly t solutions? (For example, consider the case n = 9, t = 10000.)
185. [M23] What is the largest number of solutions to a strict exact cover problem
that has N1 primary items and N2 secondary items?
186. [M24 ] Consider l = 0 when Algorithm X is given the extreme problem of order n.
a) How many updates, un, does it perform when covering i in step X4?
b) How many does it perform in step X5, when the option containing x0 has size k?
c) Therefore derive (84).
187. [HM29] Let X(z) = ПХn xnzn/n! generate the sequence (xn) of (82).
a) Use (84) to prove that X(z) = eez 0z ((2t — 1)e4t — (t — 1)e3t + 2te2t + et) e-et dt.
b) Let Tr,s(z) = eezfz treate-e*dt. Prove that Tr,0(z)/r! generates (an,r+i) in (83).
c) Show that Tr,0 (z) = (Tr+1,1(z) + zr+1)/(r + 1); furthermore, when s > 0,
„ П-/Т
Tr,s (z) = (—
sk1)
+i
krk (V
(Tr-k,s+i(z)
l
) sz Л
+ z r-ke -1)sr rr!+iez-
(— e1 .
k =0
d) Therefore X(z) = 22eez-i+12T0,0(z) — (2z— 1)e3z — 5ze2z — (12z +5)ez — 12z— 18.
► 188. [M21 ] Prove that the Gould numbers {wn) = (0,1,1, 3, 9, 31,121, 523, 2469,...)
can be calculated rapidly by forming a triangle of numbers analogous to Peirce’s triangle
7.2.1.5-(i2): 0
11
321
9 643
31 22 16 12 9
121 90 68 52 40 31
July 26, 2019
84 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
Here the entries wni, wn2, ... , wnn of the nth row obey the simple recurrence saddle point method
tail of a random set permutation
wnk = ^(n-i)k + ^n(k+i), if 1 < k < n; ш„„ = W(n—i)i, if n > 2; probability distribution
generating function
and initially w11 = 0, w22 = 1. Hint: Give a combinatorial interpretation of wnk. variance
updates
189. [HM34] Let pn = wn — gwn (see (86)). We’ll prove that |pn| = O(e "/ln2"—„), matching
complete graphs
by applying the saddle point method to R(z) = n^n pnzn/n! = ee f^ e-e dt. The idea recurrences
is to show that |R(z)| is rather small when z = £ei®, where £e^ = n as in 7.2.1.5-(24). bounded permutation problem
dual
a) Express |eez | and |e-ez | in terms of x and y when z = x + iy. conjugate
b) If 0 < 9 < n, y = £ sin 9 < 3, 0 < c1 < cos 3, prove |R(£ei®)| = O(exp(e? — c1e?)). inverses
permutations
c) If 0 < 9 < n, y = £sin9 > 3, 0 < C2 < 8, prove |R(£ei®)| = O(exp(e5 — C2e5/£)).
d) Consequently pn i/~„ i = O(e-n/ln n), as desired.
190. [HM46] Study the signs of the residual quantities pn = wn — gwn in exercise 189.
191. [HM22] The length of the tail of a random set permutation is known to have a
probability distribution whose generating function is G(z) = j'/' e-x(1 + x)zdx — 1 =
52fe=1 gkzk- (The first few probabilities in this distribution are
(gi, g2,...,g9) w (.59635, .26597, .09678, .03009, .00823, .00202, .00045, .00009, .00002);
see answer 189.) What is the average length? What is the variance?
192. [HM29] What’s the asymptotic value of ggn when n is large?
193. [M21 ] Why do (87) and (88) count updates when matching in complete graphs?
194. [HM23] Consider recurrences of the form X(t+ 1) = at + tX(t — 1). For example,
at = 1 yields the total number of nodes in the search tree for matching Kt+1.
a) Prove that 1 + 2q + (2q)(2q — 2) + • • • + (2q)(2q — 2) ... (2) = |_e1/22qq!J.
b) Find a similar “closed formula” for 1 + (2q — 1) + (2q — 1) (2q — 3) + • • • + (2q — 1) •
(2q — 3)... (3)(1). Hint: Use the fact that ex erf(^x) n>0 xn+1/2/(n + 1/2)!.
c) Estimate the solution U(2q + 1) of (87) to within O(1).
d) Similarly, give a good approximation to the solution U (2q) of (88).
► 195. [M22] Approximately how many updates does Algorithm X perform, when it is
asked to find all of the perfect matchings of the graph (89)?
► 196. [M29] Given a bounded permutation problem defined by a1... an, consider the
“dual” problem defined by b1 . . . bn , where bk is the number of j such that 1 < j < n
and aj > n + 1 — k. [Equivalently, bn . . . b1 is the conjugate of the integer partition
an . . . a1, in the sense of Section 7.2.1.4.]
a) What is the dual problem when n = 9 and a1 . . . a9 = 246677889?
b) Prove that the solutions to the dual problem are essentially the inverses of the
permutations that solve the original problem.
c) If Algorithm X begins with an a1-way branch on item X1 , how many updates
does it perform while preparing for the subproblems at depth 1 of its search tree?
d) How many solutions does a b ounded permutation problem have, given a 1 . . . an ?
e) Give a formula for the total number of updates, assuming that the algorithm
always branches on Xj at depth j — 1 of the search tree.
f) Evaluate the formula of (e) when aj = n for 1 < j < n (that is, all permutations).
g) Evaluate the formula of (e) when aj = min(j+1, n) for 1 < j < n.
h) Evaluate the formula of (e) when aj = min(2j, n) for 1 < j < n.
i) Show, however, that the assumption in (e) is not always correct. How can the
total updates be calculated correctly in general?
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—FIRST SET 85
197. [M25] Let P (a1, . . . , an) be the set of all permutations p1 . . . pn that solve the bounded permutation problem
bounded permutation problem for a1 ... an, given a1 < a2 < • • • < an and aj > j. cycles
inversions
a) Prove that P(a1,... , an) = {(ntn)... (2t2)(1t1) | j < tj < an for 1 < j < n}. generating functions
b) Also prove that P(ai,... , an) = {ffntn ... ff2t2 ait1 | j < tj < an for 1 < j < n}, Analyze
3D matching
where ast is the (t + 1 — s)-cycle (t t—1 ... s+1 s). Bjorklund
c) Let C(p) be the number of cycles in the permutation p, and let I(p) be the number polynomial algebra
of inversions. Find the generating functions 3D matching problem
randomized algorithm
q.s.
C (a1, . . . , an) = zC(p) and I(a1, . . . , an) = zI(p). bipartite matching problem
(
peP ai,...,an ) (
peP ai,...,an ) MRV
binary operation
198. [M25] Let nrs = Pr(pr = s), when p is a random element of P(a1,... , an). identity element
a) Compute these probabilities when n = 9 and a1a2 . . . a9 = 255667999. associative
b) If r < r' and s < s', show that nrs/nrs/ = nris/nrisi, when nrs/nr/s/ = 0.
199. [M25] Analyze the behavior of Algorithm X on the 3D matching problem whose
options are ‘ai bj ck’ for 1 < i, j < n and 1 < k < (i < m? m — 1: n).
► 200. [HM25] (A. Bjorklund, 2010.) We can use polynomial algebra, instead of back
tracking, to decide whether or not a given 3D matching problem is solvable. Let the
items be {a1 , . . . , an }, {b1 , . . . , bn }, {c1 , . . . , cn }, and assign a symbolic variable to each
option. If X is any subset of C, let Q(X) be the n x n matrix whose entry in row i
and column j is the sum of the variables for all options ‘ai bj ck’ with ck / X.
For example, suppose n = 3. The seven options t: ‘a1 b1 c2’, u: ‘a1 b2 c1’, v: ‘a2
b3 c2’, w: ‘a2 b3 c3’, x: ‘a3 b1 c3’, y: ‘a3 b2 c1’, z: ‘a3 b2 c2’ yield the matrices
X = 0 {сз} {c2} {с2,сз} {ci} {ci,C3} {ci,C2}
/t u 0 \ /t 0 \/ 0 u 0 \ / 0 u 0 \/ t 0 0 \ / t 00 \/ 000 \
u
Q(X) = 0 0 v+w 0 0 v 0 0w 0 0 0 0 0 v+w 00 v 0 0 w
x y+z 0 0 y+z 0 x y 0 0 y 0 x z 0 0z 0 x 0 0
is the sum of r monomials, each with coefficient ±1. (In the given example it is
uvx — twy.) Hint: Consider the case where all possible options are present.
b) Use this fact to design a randomized algorithm that decides q.s. whether or not a
matching exists, in O(2nn4) steps.
► 201. [M30] Consider the bipartite matching problem that has 3n options, ‘Xj Yk’ for
1 < j, k < n and (j — k) mod n { {0,1, n — 1}. (Assume that n > 3.)
a) What “natural, intuitively obvious” problem is equivalent to this one?
b) How many solutions does this problem have?
c) How many updates does Algorithm X make when finding all solutions, if the
items are ordered Xi , Yi , . . . , Xn , Yn , and if exercise 9 is used in step X3?
202. [13] What is
d
® D
203. [M15] Equation (95) shows that the binary operation T ф T' on search trees has
an identity element, ’■’. Is that operation (a) associative? (b) commutative?
July 26, 2019
86 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
204. [M25] True or false: Node aa' is dominant in T фT' if and only if a is dominant minimally dominant
in T and a' is dominant in T'. Hint: Express deg(aa') in terms of deg(a) and deg(a'). SAT solver
focus
205. [M28] Prove Lemma D, about the structure of T ф T'. activity scores
damping factor
206. [20] If T is minimally dominant and deg(root(T)) < deg(root(T')), show that MRV heuristic
it’s easy to describe the tree T ф T'. Y pentomino
Y pentominoes
207. [35] The principal SAT solver that we shall discuss later, Algorithm 7.2.2.2C, secondary item
bipairs
maintains focus by computing “activity scores,” which measure recent changes to the bitriple
data structures. A similar idea can be applied to Algorithm X, by computing the score bipair
Langford pair problem
ai = pt1 + pt2 + • • • , for each item i, n queens problem
sudoku
where p (typically 0.9) is a user-specified damping factor, and where i’s list of active canonical
set partitions
options was modified at times t - t1, t - t2, . . . ; here t denotes the current “time,” as restricted growth string
measured by some convenient clock. When step X3 chooses an item for branching, the lexicographically less
MRV heuristic of exercise 9 rates i by its degree Ai = LEN(i); the new heuristic replaces
this by
., = / Ai, if Ai < 1;
i I 1 + Ai/(1 + Mai), if Ai > 2.
Here // is another user-specified parameter. If // = 0, decisions are made as before;
but larger and larger values of // cause greater and greater attention to be given to the
recently active items, even if they have a somewhat large degree of branching.
a) For example, suppose ai = 1, aj = 1/2, and // = 1. Which item will be preferable,
i or j , if len(i) = len(j ) + 1 and 0 < len(j) < 4?
b) What modifications to Algorithm X will implement this scheme?
c) What values of p and // will avoid exponential growth, when applied to n inde
pendent copies of the toy problems (go) and (92)?
d) Does this method save time in the Y pentomino problem of Fig. 73?
► 208. [21 ] Modify the exact cover problem of Fig. 73 so that none of the Y pentominoes
that occur in an ‘H’ or ‘ ’ have been flipped over. Hint: To prevent the flipped-over
Y’s marked 8 and b from occurring simultaneously, use the options ‘1a 2a 3a 4a 2b V1b’
and ‘1c 2c 3c 4c 3b V1b’, where V1b is a secondary item.
209. [20] Improve the search tree (93) in the same way that (100) improves on (91),
by considering two bipairs of (92).
210. [21 ] A “bitriple” (a,e,Y; a',e/,Y/) is analogous to a bipair, but with (97) re
placed by a + в + Y = a' + в + Y'• How can we modify an exact cover problem so that
it excludes all solutions in which options a', в, and 7' are simultaneously present?
211. [20] Do the options of the text’s formulation of the Langford pair problem have
any bipairs? How about the n queens problem? And sudoku?
► 212. [M21 ] If the primary items of an exact cover problem have been linearly ordered,
we can say that the bipair (a, в; a', в') is canonical if (i) the smallest item in all
four options appears in a and a'; and (ii) option a is lexicographically smaller than
option a', when their items have been listed in ascending order.
a) Prove that Theorem S applies to exact coverings that are strong according to this
definition of canonicity. Hint: Show that it’s a special case of the text’s definition.
b) Does such an ordering justify the choices made in (99)?
213. [M21 ] If n and П are two partitions of the same set, say that п < п' if the
restricted growth string of п is lexicographically less than the restricted growth string
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—FIRST SET 87
of п'. Let (a, в; a', в') be a canonical bipair in the sense of exercise 212. Also let п be strong solutions
a partition of the items such that a and в are two of its parts, and let п' be the same perfect matching
complete graph
partition but with a' and в' substituted. Is п < п'? X2C problem
► 214. [21 ] Under the assumptions of Theorem S, how can the set of all solutions to an bipairs
canonical bipair
exact cover problem be found from the set of all strong solutions? secondary item
► 215. [M30] The perfect matching problem on the complete graph K2q+1 is the X2C pentominoes
forcing
problem with 2q+1 primary items {0,.. . , 2q} and (2q+1) options ‘i j’ for 0 < i < j < 2q. stack
a) How many bipairs are present in this problem? spacer
b) Say that (i, j, k,l) is excluded if there’s a canonical bipair (а, в; a', в') for which
a' = ‘i j’ and в' = ‘k l’. Prove that, regardless of the ordering of the options,
the number of excluded quadruples is 2/3 of the number of bipairs.
c) What quadruples are excluded when the options are ordered lexicographically?
d) We reduce the amount of search by introducing a secondary item (i, j, k, l) for
each excluded quadruple, and appending it to the options for ‘i j’ and ‘k l’.
Describe the search tree when this has been done for the quadruples of (c).
e) Show that only ©(q3) excluded quadruples suffice to obtain that search tree.
f) Order the options cleverly so that the search tree has only 2q + 1 nodes.
g) How many excluded quadruples suffice to obtain that search tree?
216. [25] Continuing exercise 215, experiment with the search trees that are obtained
by (i) choosing a random ordering of the options, and (ii) using only m of the quadruples
that are excluded by that ordering (again chosen at random).
217. [M32] A bipair of pentominoes (a, в; a', в') is a configuration such as
where two pentominoes occupy a 10-cell region in two different ways. In this example
we may write a = S + 00 + 01 + 11 + 12 + 13, в = Y + 02 + 03 + 04 + 05 + 14, a' =
S + 04 + 05 + 12 + 13 + 14, в' = Y+00+01 + 02 + 03+11; hence a+в = a' + в' as in (97).
Compile a complete catalog of all bipairs that are possible with distinct pentomi-
noes. In particular, show that each of the twelve pentominoes participates in at least
one such bipair. (It’s difficult to do this by hand without missing anything. One good
approach is to exploit the equation a — a' = - (в — вО: First find all the delta values
±(a — a') for each of the twelve pentominoes individually; then study all deltas that
are shared by two or more of them. For example, the S and Y pentominoes both have
00 + 01 — 04 — 05 + 11 — 14 among their deltas.)
► 218. [20] Why must i be uncolored, in the definition of “forcing” for Algorithm P?
219. [20] Suppose p and q are primary items of an XCC problem, and that every option
containing p or q includes an uncolored instance of either i or j (or both), where i and
j are other items; yet p and q never occur in the same option. Prove that every option
that contains i or j , but neither p nor q, can be removed without changing the problem.
220. [28] Step P5 of Algorithm P needs to emulate step C5 of Algorithm C, to see if
some primary item will lose all of its options. Describe in detail what needs to be done.
221. [23] After all options that begin with item i have been examined in step P5, those
that were found to be blocked appear on a stack, starting at S . Explain how to delete
them. Caution: The problem might become unsolvable when an option goes away.
222. [22] Before item i is deleted in step P7, it should be removed from every option
that contains S , by changing the corresponding node into a spacer. All options that
involve i but not S should also be deleted. Spell out the low-level details of this process.
July 26, 2019
88 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
223. [20] Implement the output phase of Algorithm P (step P10). rounds
pentomino problem
► 224. [M21 ] Construct an exact cover problem with O(n) options that causes Algo Langford pairing
rithm P to perform n rounds of reduction (that is, it executes step P2 n times). reverse
reflected string
225. [21 ] Why does Algorithm P remove 235 options in the 6 x 10 pentomino problem, lexicographically
but only 151 options in the 6 x 15 case? *®
SCRABBLE
4-letter
226. [M20] Assume that a1... a2n is a Langford pairing, and let ak = a2n+1-k so that 5-letter
al ... a'2n is the reverse of a1 ... a2n. Are there any obvious relations between the sums word rectangles
English
min-cost exact cover
Si = Ek=i kak, Si = £k=i kak, S2 = Ek=x k2ak, S2 = Ek=i *24? 16 queens problem
doubly symmetric
What about the analogous sums S E,= 1 kak and S' Ek=1 k(ak)2? prime square problem
227. [10] What cost should be assigned to option (16), to minimize (a) S2? (b) S?
228. [M30] The Langford pairings for n = 16 that minimize S2 turn out to be precisely
the 12,016 pairings that minimize Si ; and their reversals turn out to be precisely the
12,016 pairings that maximize both S2 and Si. Is this surprising, or what?
► 229. [25] What Langford pairings for n =16 are lexicographically smallest and largest?
230. [20] Explain how Algorithm X$, which minimizes the sum of option costs, can
also be used to maximize that sum, in problems like that of Fig. 74.
231. [21 ] What’s the maximum *SCRABBLE
® -like score you can achieve by filling the
grid below with 4-letter and 5-letter words that all are among the (a) 1000 (b) 2000
(c) 3000 most common words of English having that many letters?
238. [24] Find 3xn arrays filled with distinct 3-digit and n-digit primes, for 3 < n < 7, word rectangles
having the minimum and maximum possible product. set cover
exact cover
► 239. [M27] Given a family {S1,. .. , Sm} of subsets of {1,... ,n}, together with posi preprocessing
connected regions
tive weights (w1 , . . . , wm), the optimum set cover problem asks for a minimum-weight weight
way to cover {1, . . . , n} with a union of Sj ’s. Formulate this problem as an optimum induced subgraphs
exact cover problem, suitable for solution by Algorithm X$. Hint: Maximize the weight interior cost
exterior costs
of all sets that do not participate in the cover. USA graph
240. [16] What usable 6-state options include mt and tx in the USA-partition problem? New York
New England
241. [21 ] Does preprocessing by Algorithm P remove the useless option (114)? tax
cutoff threshold
► 242. [M23] Extend the algorithm of exercise 7.2.2-78 so that it visits only subgraphs online algorithm
that don’t cut off connected regions whose size isn’t a sum of integers in [L . . U). every kth cost
243. [M20] Assume that every item i of an XCC problem has been given a weight wi ,
and that every solution to the problem involves exactly d options. If the cost of every
option is $(x2), where x is the sum of the option’s weights, prove that every minimum
cost solution also minimizes dk=1 (xk - r)2 , for any given real number r.
For example, suppose d = 6, k = 2, and 9 = 16. If costs appear in the order pi as source
(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8), your algorithm should stop after seeing the 2. sudoku
Langford pairs
250. [21 ] Users of Algorithm C$ are allowed to supply hints that speed up the com ZDD
MRV heuristic
putation, by specifying (i) a set Z of characters, such that every element of Z is the hide7
first character of exactly one primary item in every option; also (ii) a number z > 0, unhide
meaning that every option contains exactly z primary items whose names don’t begin purified
analysis of algorithms
with a character in Z. (For example, Z = {p, r, c, b} in the sudoku options (30); z = 1
perfect matchings
in options (110). In the options (16) for Langford pairs, we could change the name of matchings
each numeric item i to ‘!i’, then let Z = {!} and z = 2.) Explain how to use these hints Fibonacci numbers
extreme
to supply an early-cutoff test at the beginning of step C3$, as explained in the text. bounded permutation problem
bipartite matching
251. [18] If a given problem is solvable, when does Algorithm Z first discover that fact? bipartite matching problems
► 252. [20] Algorithm Z produces the ZDD (120) from the options (121) if step Z3 seats at a circular table
circular table
simply chooses the leftmost item i1 = root(0) instead of using the MRV heuristic.
What ZDD would have been obtained if the method of exercise 9 had been used instead?
► 253. [21 ] Extend Algorithm Z so that it reports the total number of solutions.
► 254. [28] The signature a computed by Algorithm Z in step Z2 is supposed to char
acterize the current subproblem completely. It contains one bit for each primary item,
indicating whether or not that item still needs to be covered.
a) Explain why one bit isn’t sufficient for secondary items with colors.
b) Suggest a good way to implement the computation of a.
c) Algorithm C uses the operations hide' and unhide' in (go)-(57), in order to
avoid unnecessary accesses to memory in nodes for secondary items. Explain
why Algorithm Z does not want to use those optimizations. Hint: Algorithm Z
needs to know whether the option list for a secondary item is empty.
d) When the list for item i is purified, its options of the wrong color are removed from
other lists. But they remain on list i, in order to be unpurified later. How then
can Algorithm Z know when list i is no longer relevant to the current subproblem?
255. [HM29] Express the exact number of updates made by Algorithm Z when it finds
the perfect matchings of KN , as well as the exact number of ZDD nodes produced, in
terms of Fibonacci numbers. Hint: See exercise 193.
► 256. [M23] What is the behavior of Algorithm Z when it is asked to find all perfect
matchings of the “bizarre” graph (89)?
► 257. [21 ] How does Algorithm Z do on the “extreme” exact cover problem, with n
items and 2n - 1 options? (See the discussion preceding (82).)
a) What signatures are formed in step Z2?
b) Draw the schematic ZDD, analogous to (123), when n = 4.
258. [HM21 ] How many updates does Algorithm Z perform, in that extreme problem?
259. [M25] Exercise 196 analyzes the behavior of Algorithm X on the bounded per
mutation problem defined by a1 . . . an. Show that Algorithm Z is considerably faster,
by determining the number of memos, ZDD nodes, and updates when a1a2 . . . an-1an
is (a) nn . . . nn [with n! solutions]; (b) 2 3 . . . nn [with 2n-1 solutions]. Assume that
the items are X1 , X2, . . . , Xn, Y1, Y2, . . . , Yn, in that order.
260. [M21] Exercises 14 and 201 are bipartite matching problems related to choosing
seats at a circular table. Test Algorithm Z empirically on those problems, and show
that it solves the latter in linear time (despite exponentially many solutions).
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—FIRST SET 91
► 261. [23] Let G be a directed acyclic graph, with source vertices S and sink vertices T. vertex-disjoint
a) Use Algorithm C (or Z) to find all sets of m vertex-disjoint paths from S to T. parallominoes
knights
b) Also find all such sets of paths from sk to tk for 1 < k < m, given sk and tk. random solutions of XCC problems
c) Apply (a) to find all sets of n — 1 disjoint paths that enter an n x n square at the domino tilings
Aztec diamond
north or east edge, proceed by south and/or west steps, and exit at the south or bipartite matching problems
west edge, avoiding the corners. (A random 16 x 16 example is shown.) diamond tilings
simplex
1 2 3 4 5 6 7 8
3 4 1 2 0 8 5 6 16 queens problem
1 2 3 8 5 6 0 7 pentominoes
4 8 5 2 3 7 0 0
5 1 4 8 6 2 3 7 MacMahon’s triangle problem
0 0 0 1 4 7 6 2 de Bruijn sequences
0 5 8 7 6 1 4 3
8 7 6 5 4 3 2 1 word stair
word search
d) Apply (b) to find all vertex-disjoint, downward paths of eight knights that start kakuro
on the top row of a chessboard and end on the bottom row in reverse order. MRV heuristic
ordered ZDD
► 262. [M23] One of the advantages of Algorithm Z is that a ZDD allows us to generate reduced ZDD
uniformly random solutions. (See the remarks following 7.1.4-(1з).)
a) Determine the number of ZDD nodes output by Algorithm Z for the set of all
domino tilings of Sn , where Sn is the shape obtained after right triangles of side 7
have been removed from each corner of a 16 x n rectangle:
How many tilings are possible for S16 (the Aztec diamond of order 8)? For S32?
b) Similarly, determine the ZDD size for the family of all diamond tilings of Tn —
the grid simplex (n + 16, n + 8, 16, n + 8, 0, 0, 0), a hexagon of sides (8, 8, n, 8, 8, n):
263. [24] Compare the time and space requirements of Algorithms C and Z when they
are applied to (a) the 16 queens problem; (b) pentominoes, as in exercises 271 and 274;
(c) MacMahon’s triangle problem, as in exercise 126; (d) the generalized de Bruijn
sequences of exercise 95; (e) the “right word stair” problem of exercise 90; (f) the 6 x 6
“word search” problem of exercise 105; (g) the kakuro problem in exercise 431.
264. [M21 ] Suppose step Z3 always chooses the first active item i = rlink(0), instead
of using the MRV heuristic, unless some other active item has len(i) = 0. Prove that
Algorithm Z will then output an ordered ZDD.
► 265. [22] Prove that Algorithm Z will never produce identical ZDD nodes (Oi? li: hi) =
(Oj? lj: hj) for i = j, if all items are primary. But secondary items can cause duplicates.
267. [18] Using Conway’s piece names, pack five pentominoes into the shape
so that they spell a common English word when read from left to right.
► 268. [21 ] There are 1010 ways to pack the twelve pentominoes into a 5 x 12 box, not
counting reflections. What’s a good way to find them all, using Algorithm X?
269. [21 ] How many of those 1010 packings decompose into 5 x k and 5 x (12- k)?
270. [21 ] In how many ways can the eleven nonstraight pentominoes be packed into
a5x 11 box, not counting reflections as different? (Reduce symmetry cleverly.)
271. [20] There are 2339 ways to pack the twelve pentominoes into a 6 x 10 box, not
counting reflections. What’s a good way to find them all, using Algorithm X?
272. [23] Continuing exercise 271, explain how to find special kinds of packings:
a) Those that decompose into 6 x k and 6 x (10-k).
b) Those that have all twelve pentominoes touching the outer boundary.
c) Those with all pentominoes touching that boundary except for V, which doesn’t.
d) Same as (c), with each of the other eleven pentominoes in place of V.
e) Those with the minimum number of pentominoes touching the outer boundary.
f) Those that are characterized by Arthur C. Clarke’s description, as quoted below.
That is, the X pentomino should touch only the F (aka R), the N (aka S), the U, and
the V—no others.
Very gently, he replaced the titanite cross
in its setting between the F, N, U, and V pentominoes.
— ARTHUR C. CLARKE, Imperial Earth (1976)
273. [25] All twelve pentominoes fit into a 3 x 20 box only in two ways, shown in (36).
a) How many ways are there to fit eleven of them into that box?
b) In how many solutions to (a) are the five holes nonadjacent, kingwise?
c) In how many ways can eleven pentominoes be packed into a 3 x 19 box?
274. [21 ] There are five different tetrominoes, namely
; ;
square straight skew ell tee
In how many essentially different ways can each of them be packed into an 8 x 8 square
together with the twelve pentominoes?
275. [21] If an 8x8 checkerboard is cut up into thirteen pieces, representing the twelve
pentominoes together with one of the tetrominoes, some of the pentominoes will have
more black cells than white. Is it possible to do this in such a way that U, V, W, X,
Y, Z have a black majority while the others do not?
276. [18] Design a nice, simple tiling pattern that’s based on the five tetrominoes.
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—SECOND SET 93
277. [25] How many of the 6 x 10 pentomino packings are strongly three-colorable, in three-colorable
the sense that each individual piece could be colored red, white, or blue in such a way graph coloring
bipairs
that no pentominoes of the same color touch each other — not even at corner points? strong solutions
Benjamin
► 278. [32] Use the catalog of bipairs in exercise 217 to reduce the number of 6 x 10 pen- cube, wrapped
tomino packings, listing strong solutions only (see Theorem S). How much time is saved? Knuth, Jill
Garcia, Hector
279. [40] (H. D. Benjamin, 1948.) Show that the twelve pentominoes can be wrapped Mobius strip
around a cube of size 10 x 10 x 10. For example, here are front and back views faultfree
checkerboard
of such a cube, made from twelve colorful fabrics by the author’s wife in 1993: Aztec diamond
symmetric
Kaplan
fence
holes
tatami
crossroads
Golomb
(Photos by
Hector Garcia)
What is the best way to do this, minimizing undesirable distortions at the corners?
► 280. [M26] Arrange the twelve pentominoes into a Mobius strip of width 4. The
pattern should be “faultfree”: Every straight line must intersect some piece.
► 281. [20] The white cells of a (2n+1 x (2n+1) checkerboard, with black corners, form
an interesting graph called the Aztec diamond of order n; and the black cells form the
Aztec diamond of order n+1/2. For example, the diamonds of orders 11/2 and 13/2 are
and
where (ii) has a “hole” of order 3/2. Thus (i) has 61 cells, and (ii) has 80.
a) Find all ways to pack (i) with the twelve pentominoes and one monomino.
b) Find all ways to pack (ii) with the 12 pentominoes and 5 tetrominoes.
Speed up the process by not producing solutions that are symmetric to each other.
► 282. [22] (Craig S. Kaplan.) A polyomino can sometimes be surrounded by non
overlapping copies of itself that form a fence: Every cell that touches the polyomino —
even at a corner — is part of the fence; conversely, every piece of the fence touches the
inner polyomino. Furthermore, the pieces must not enclose any unoccupied “holes.”
Find the (a) smallest and (b) largest fences for each of the twelve pentominoes.
(Some of these patterns are unique, and quite pretty.)
283. [22] Solve exercise 282 for fences that satisfy the tatami condition of exercise
7.1.4-215: No four edges of the tiles should come together at any “crossroads.”
► 284. [27] Solomon Golomb discovered in 1965 that there’s only one placement
of two pentominoes in a 5 x 5 square that blocks the placement of all the others.
Place (a) {I, P, U, V } and (b) {F, P, T, U} into a 7 x 7 square in such a
way that none of the other eight will fit in the remaining spaces.
July 26, 2019
94 combinatorial searching (f5c: 26 Jul 2019 @ 2051) 7.2.2.1
285. [21 ] (T. H. O’Beirne, 1961.) The one-sided pentominoes are the eighteen distinct O’Beirne
5-cell pieces that can arise if we aren’t allowed to flip pieces over: one-sided pentominoes
flip pieces over
princess
max-cost solution
circle, discrete
one-sided pentominoes
Notice that there now are two versions of P, Q, R, S, Y, and Z. polyforms of polyforms
tetrominoes
In how many ways can all eighteen of them be packed into rectangles? checkered
286. [21 ] If you want to pack the twelve pentominoes into a 6 x 10 box without turning one-sided
trominoes
any pieces over, 26 different problems arise, depending on the orientations of the one daily puzzle
sided pieces. Which of those 64 problems has (a) the fewest (b) the most solutions? tetrominoes
► 287. [23] A princess asks you to pack an m x n box with pentominoes, rewarding you
with $c • (ni + j) if you’ve covered cell (i, j) with piece c, where c = (1, 2,... , 12) for
pieces (O, P, . . . , Z). (The most valuable packing will be “closest to alphabetic order.”)
Use Algorithm X$ to maximize your bounty when packing boxes of sizes 4 x 15,
5 x 12, 6 x 10, 10 x 6, 12 x 5, and 15 x 4. Consider also the princess’s circle-shaped
subset of a 9 x 9 box, where you are to cover only the 60 cells whose distances from the
center are between 1 and 18. How do the running times of Algorithm X$ compare to
the amounts of time that Algorithm X would take to find all solutions?
288. [21] Similarly, pack the one-sided pentominoes optimally into 9 x 10 and 10 x 9.
► 289. [29] (Pentominoes of pentominoes.) Magnify the 3 x 20 pentomino packing (36)
by replacing each of its unit cells by (a) 3 x 4 rectangles; (b) 4 x 3 rectangles. In how
many ways can the resulting 720-cell shape be packed with twelve complete sets of
twelve pentominoes, using one set for each of the original pentomino regions?
(c) Also partition the 720-cell shape below into 3 x 20 approximately square 12
cell regions, by assigning each gray cell to an adjacent region. (This shape has been
superimposed on a grid whose 12 x 12 regions are perfectly square.) Minimize the
total perimeter of the 60 resulting regions, and try for a pleasantly symmetrical solution.
290. [21] When tetrominoes are both checkered and one-sided (see exercises 275 and
285), ten possible pieces arise. In how many ways can all ten of them fill a rectangle?
291. [24] (A puzzle a day.) Using the two trominoes, the five tetrominoes, and three
of the pentominoes, one can cover up 11 of the 12 “months” and 30 of the 31 “days”
in the following pair of diagrams, thereby revealing the current month and day:
1 2 3 4 5 6 7
I II III IV 8 9 10 11 12 13 14
V VI VII VIII 15 16 17 18 19 20 21
IX X XI XII 22 23 24 25 26 27 28
29 30 31
Which of the 132 sets of three pentominoes always allow this to be done?
296. [41 ] Perhaps the nicest hexomino packing uses a 5 x 45 rectangle with 15 holes
proposed by W. Stead in 1954. In how many ways can the 35 hexominoes fill it?
297. [24] (P. Torbijn, 1989.) Can the 35 hexominoes be packed into six 6 x 6 squares?
► 298. [22] In how many ways can the twelve pentominoes be placed into
an 8 x 10 rectangle, leaving holes in the shapes of the five tetrominoes?
(The holes should not touch the boundary, nor should they touch each
other, even at corners; one example is shown at the right.) Explain how
to encode this puzzle as an XCC problem.
299. [39] If possible, solve the analog of exercise 298 for the case of 35 hexominoes in
a 5 x 54 rectangle, leaving holes in the shapes of the twelve pentominoes.
► 300. [23] In how many ways can the twelve pentominoes be arranged in a 10 x 10
square, filling exactly six of the cells in every row and exactly six of the cells in every
column, if we also require that (a) the cells on both diagonals are completely empty?
(b) the cells on both diagonals are completely filled? (c) the design is really interesting?
July 26, 2019
96 COMBINATORIAL SEARCHING (F5C: 26 Jul 2019 @ 2051) 7.2.2.1
301. [25] Here’s one way to place the twelve pentominoes into a 5 x 5 square, covering small polyominoes
the cells of rows (1, 2, 3, 4, 5) exactly (2, 3, 2, 3, 2) times: slim polyominoes
nonominoes
jigsaw sudoku
QY SX ST ST RT pi as src
QXY XYZ RXZ RST RSV parallelogram polyomino
parallomino
QY XZ UW RT UV staircase polygon
skew Young tableau
QYZ QWZ UVW PUV PUV Young tableaux
skew Ferrers board
OW OW OP OP OP
Ferrers diagrams
tableaux
a) How many such placements are possible? partitions
trees
b) Suppose we’ve placed O first, P next, Q next, . . . , Z last, when making the path length
arrangement above. Then Z is above W is above V is above U is above P is above O; generating function
hence the pentominoes have been stacked up on six levels. Show that a different NP-complete
polyominoes
order of placement would require only four levels. grid, rotated
c) Find a solution to (a) that needs only three levels. parity
two-layer pieces
d) Find a solution to (a) that can’t be achieved with only four levels. windmill dominoes
302. [26] Say that an n-omino is “small” if it fits in a ( n + 1) x ( n + 1) box, and
“slim” if it contains no 2 x 2 tetromino. Thus, for example, pentominoes O, Q, S, Y
aren’t small; P isn’t slim.
a) How many nonominoes are both small and slim?
b) Fit nine different small-and-slim nonominoes into a 9 x 9 box.
c) Use a solution to (b) as the basis of a jigsaw sudoku puzzle with a unique solution.
The clues of your puzzle should be the initial digits of n.
► 303. [HM35] A parallelogram polyomino, or “parallomino” for short, is a polyomino
whose boundary consists of two paths that each travel only north and/or east. (Equiva
lently, it is a “staircase polygon,” “skew Young tableau,” or a “skew Ferrers board,” the
difference between the diagrams of two tableaux or partitions; see Sections 5.1.4 and
7.2.1.4.) For example, there are five parallominoes whose boundary paths have length 4:
a) Find a one-to-one correspondence that maps the set of ordered trees with m leaves
and n nodes into the set of parallominoes with width m and height n - m. The
area of each parallomino should be the path length of its corresponding tree.
b) Study the generating function G(w, x, y) = parallominoes wareaxwidthyheight.
c) Prove that the parallominoes whose width-plus-height is n have total area 4n-2.
d) Part (c) suggests that we might be able to pack all of those parallominoes into a
2n-2 x 2n-2 square, without rotating them or flipping them over. Such a packing
is clearly impossible when n = 3 or n = 4; but is it possible when n = 5 or n = 6?
304. [M25] Prove that it’s NP-complete to decide whether or not n given polyominoes,
each of which fits in a ©(log n) x ©(logn) square, can be exactly packed into a square.
305. [25] When a square grid is scaled by 1Д/2 and rotated 45°, we can
place half of its vertices on top of the original ones; the other “odd-parity”
vertices then correspond to the centers of the original square cells.
Using this idea we can glue a small domino of area 1 over portions
of an ordinary domino of area 2, thereby obtaining ten distinct two-layer
pieces called the windmill dominoes:
July 26, 2019
7.2.2.1 dancing links: exercises—second set 97
Grabarchuk
snake-in-the-box cycle
coil-in-the-box
straight trominoes
domino
polyiamond
moniamonds
diamonds
a) Arrange four windmill dominoes so that the upper layer resembles a windmill. triamonds
lozenges, see diamonds
b) Place all ten windmill dominoes inside a 4 x 5 box, without overlapping. tetriamonds
c) Similarly, pack them all into a 2 x 10 box. pentiamonds
d) Place them so that the upper layer fills a (4/ 2) x (5/ 2) rectangle. one-sided
hexiamonds
e) Similarly, fit the upper layer into a (2/ 2) x (10/ 2) rectangle. Conway
In each case (a)-(e), use Algorithm X to count the total number of possible placements.
Also look at the output and choose arrangements that are especially pleasing.
► 306. [30] (S. Grabarchuk, 1996.) In how many ways can the ten windmill dominoes
be arranged so that the 20 large squares define a snake-in-the-box cycle, in the sense
of exercise 172(b), and so do the 20 small squares? (For example, arrangements like
A BCD
• EF
I G HIJ K L
a) How many base placements do they have?
b) In how many ways can they be packed into convex polygons, as in exercise 308?
310. [23] What’s the smallest m for which the 12 hexiamonds fit without overlap in
m----------------- m
► 311. [30] (Hexiamond wallpaper.} Place the twelve hexiamonds into a region of N wallpaper
triangles, so that (i) shifted copies of the region fill the plane; (ii) the hexiamonds of the octahedron
wrapping a polyhedron
resulting infinite pattern do not touch each other, even at vertices; (iii) N is minimum. polyforms of polyforms
whirl
312. [22] The following shape can be folded, to cover the faces of an octahedron: dodeciamond
Sicherman
pentiamonds
congruent pairs
polyhex
hexagons
Chemists
anthracene
phenanthrene
Fill it with hexiamonds so that they cross the folded edges as little as possible. phenalene
aromatic hydrocarbons
► 313. [29] (Hexiamonds of hexiamonds.) A “whirl,” shown here, is an inter grid, hexagonal
esting dodeciamond that tiles the plane in a remarkably beautiful way. hexagons, coordinates for
coordinates
If each triangle ‘д’ of a hexiamond is replaced by a whirl, in how many ways can base placements
the resulting 72-triangle shape be packed with the full set of hexiamonds? (Exercise rosette
289 discusses the analogous problem for pentominoes.) tetrahexes
polyforms of polyforms
Consider also using “flipped whirls,” the left-right reflections of each whirl. rosette
► 314. [28] (G. Sicherman, 2008.) Can the four pentiamonds be used to make two
10-iamonds of the same shape? Formulate this question as an exact cover problem.
315. [20] A polyhex is a connected shape formed by pasting hexagons together at
their edges, just as polyominoes are made from squares and polyiamonds are made from
triangles. For example, there’s one monohex and one dihex, but there are three trihexes.
Chemists have studied polyhexes since the 19th century, and named the small ones:
benzene = naphthalene =
(Groups of six carbon atoms can bond together in a nearly planar fashion, forming long
chains of hexagons, with hydrogen atoms attached. But the correspondence between
polyhexes and polycyclic aromatic hydrocarbons is not exact.)
Represent the individual hexagons of an infinite grid by Cartesian-like coordinates
51 41 31 21 11 01 11 21 31 41
^о^о^о^оГооТ1оТ2^Гз^Г4оГ
41T31T21Т11Ji01Т11Т21Т31Т41Т51
where 1 = -1, 2 = -2, etc. Extending exercises 266 and 308(a), explain how to find the
base placements of a polyhex, given the coordinates of its cells when placed on this grid.
316. [20] Show that the complete set of trihexes and tetrahexes can be packed nicely
into a rosette that consists of 37 concentric hexagons. In how many ways can it be done?
317. [22] (Tetrahexes of tetrahexes.) If we replace each hexagon of a tetrahex by a
rosette of seven hexagons, we get a 28-hex. In how many ways can that scaled-up shape
be packed with the seven distinct tetrahexes? (See exercises 289 and 313.)
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—SECOND SET 99
► 318. [20] Let’s say that the T-grid is the set of all hexagons xy with x ^ y (modulo 3): T-grid
triangular grid
polyiamond
Х5ц5Сс?Ц?и5Ц°ц1ц?ьС3ьс11 triangles, coordinates for
coordinate system
5^J^J^2^J^°^L 1^2^C3^C4^JO polyaboloes
Collins
Х4ССзСС2ц1и?и5и?и?и?и^51Х isosceles right triangles
polyominoes, generalized
Show that there’s a one-to-one correspondence between the hexagons of the T-grid and convex
O’Beirne
the triangles of the infinite triangular grid, in which every polyiamond corresponds one-sided tetraboloes
to a polyhex. (Therefore the study of polyiamonds is a special case of the study of polysticks
p olyhexes!) Hint: Exercise 124 discusses a coordinate system for representing triangles. polylines, see polysticks
tetrasticks
319. [21] After polyominoes, polyiamonds, and polyhexes, the next most p opular polyforms
polyskews
p olyforms are the polyaboloes, originally proposed by S. J. Collins in 1961. These are squares
the shapes obtainable by attaching isosceles right triangles at their edges; for example, rhombuses
there are three diaboloes: {TT, TT, Q}. Notice that a new idea arises here, because the checkerboard
polysquarerhombi, see polyskews
square diabolo arises from two monob oloes in two ways, TT and TT , yet it counts as
only one shape. Also, any n-abolo corresponds to a 2n-abolo, when scaled up by 2.
The 14 tetraboloes can be named by using rough resemblances to hexiamonds:
ABC DE F G HIJ K L MN
Show that the study of polyaboloes can be reduced to the study of (slightly
generalized) polyominoes, just as exercise 318 reduces polyiamonds to polyhexes.
► 320. [M28] Explain how to enumerate all of the N-aboloes that are convex. How
many of the convex 56-aboloes can be packed by the fourteen tetraboloes?
321. [24] (T. H. O’Beirne, 1962.) In how many ways can a square be formed from
the eight one-sided tetraboloes and their mirror images?
322. [23] The polysticks provide us with another intriguing family
of shapes that can be combined in interesting ways. An “n-stick”
is formed by joining n horizontal and/or vertical unit line segments
together at grid points. For example, there are two disticks, and five
tristicks; they’re shown here in black, accompanied by the monostick,
and surrounded by the sixteen tetrasticks in white.
Polysticks introduce yet another twist into polyform puzzles, because we must not
allow different pieces to cross each other when we pack them into a container. Extend
exercise 266 to polysticks, so that Algorithm X can deal with them conveniently.
323. [M25] We’ve now seen polyominoes, p olyiamonds, polyhexes, . . . , p olysticks,
each of which have contributed new insights; and many other families of “polyforms”
have in fact been studied. Let’s close our survey with polyskews, a relatively new family
that seems worthy of further exploration. Polyskews are the shapes that arise when we
join squares alternately with rhombuses, in checkerboard fashion. For example, here
are the ten tetraskews:
There are two monoskews, one diskew, and five triskews. skewed rectangle
a) Explain how to draw such skewed pixel diagrams. base placements
Somap
b) Show that polyskews, like polyaboloes, can be reduced to polyominoes. Soma cube
c) In how many ways do the tetraskews make a skewed rectangle? degree sequences
connected components
► 324. [20] Extend exercise 266 to three dimensions. How many base placements do bicomponents
factorization
each of the seven Soma pieces have? W-wall
325. [27] The Somap is the graph whose vertices are the 240 distinct solutions to the Soma pieces
nonominoes
Soma cube problem, with u --- v if and only if u can be obtained from an equivalent Hein
of v by changing the positions of at most three pieces. The strong Somap is similar, Schwartz
self-supporting
but it has u --- v only when a change of just two pieces gets from one to the other. gravity
a) What are the degree sequences of the Somap graphs?
b) How many connected comp onents do they have? How many bicomponents?
► 326. [M25] Use factorization to prove that Fig. 80’s W-wall cannot be built.
327. [24] Figure 80(a) shows some of the many “low-rise” (2-level) shapes that can be
built from the seven Soma pieces. Which of them is hardest (has the fewest solutions)?
Which is easiest? Answer those questions also for the 3-level prism shapes in Fig. 80(b).
► 328. [M23] Generalizing the first four examples of Fig. 80, study the set of all shapes
obtainable by deleting three cubies from a 3 x 5 x 2 box. (Two
examples are shown here.) How many essentially different shapes
are p ossible? Which shape is easiest? Which shape is hardest?
329. [22] Similarly, consider (a) all shapes that consist of a
3 x 4 x 3 box with just three cubies in the top level; (b) all
3-level prisms that fit into a 3 x 4 x 3 box.
330. [25] How many of the 1285 nonominoes define a prism that can be realized by
the Soma pieces? Do any of those packing problems have a unique solution?
331. [M40] Make empirical tests of Piet Hein’s belief that the number of shapes
achievable with seven Soma pieces is approximately the number of 27-cubie polycubes.
332. [20] (B. L. Schwartz, 1969.) Show that the Soma pieces can make shapes that
appear to have more than 27 cubies, because of holes hidden inside or at the bottom:
which are “self-supporting” via gravity. (You may need to place a small book on top.)
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—SECOND SET 101
Fig. 80. Gallery of noteworthy polycubes that contain 27 cubies. All of them can be
built from the seven Soma pieces, except for the W-wall. Many constructions are also
stable when tipped on edge and/or when turned upside down. (See exercises 326-334.)
July 26, 2019
102 combinatorial searching (f5c: 26 Jul 2019 @ 2051) 7.2.2.1
► 334. [M32] Impossible structures can be built, if we insist only that they look genuine facades
when viewed from the front (like facades in Hollywood movies)! Find all solutions to movies
isometric
projection
three dimensions
Cube Diabolique
Diabolical Cube
Watilliaux
W-wall X-wall cube L-bert Hall
holes
dowel
that are visually correct. (To solve this exercise, you need to know that the illustrations Lavery
here use the non-isometric projection (x, y, z) ^ (30x — 42y, 14x + 10y + 45z)u from bent tricubes
three dimensions to two, where u is a scale factor.) All seven Soma pieces must be used. tricubes
dice
335. [30] The earliest known example of a polycube puzzle is the “Cube Diabolique,” tetracubes
gravity
manufactured in late nineteenth century France by Charles Watilliaux; it contains six octominoes
flat pieces of sizes 2, 3, . . . , 7: pentacubes
339. [25] How many of the 369 octominoes define a 4-level prism that can be realized
by the tetracubes? Do any of those packing problems have a unique solution?
340. [30] There are 29 pentacubes, conveniently identified with one-letter codes:
o solid pentominoes
flat pentacubes
mirror images
u v w xffil y z pentominoes
5 x 5 x 5 cube
Dowler’s Box
Pieces o through z are called, not surprisingly, the solid pentominoes or flat pentacubes. chiral
a) What are the mirror images of a, b, c, d, e, f, A, B, C, D, E, F, j, k, l, . . . , z? mirror
b) In how many ways can the solid pentominoes be packed into an a x b x c cuboid? Sillke
pentomino
c) What “natural” set of 25 pentacubes is able to fill the 5 x 5 x 5 cube? tower
factorization
► 341. [25] The full set of 29 pentacubes can build an enormous vari Y pentominoes
ety of elegant structures, including a particularly stunning example symmetries
called “Dowler’s Box.” This 7 x 7 x 5 container, first considered by cross
tripod
R. W. M. Dowler in 1979, is constructed from five flat slabs. Yet pod
only 12 of the pentacubes lie flat; the other 17 must somehow be torus, 3D
worked into the edges and corners.
Despite these difficulties, Dowler’s Box has so many solutions that we can actually
impose many further conditions on its construction:
a) Build Dowler’s Box in such a way that the chiral pieces a, b, c, d, e, f and their
images A, B, C, D, E, F all appear in horizontally mirror-symmetric positions.
b) Show that 7/9 of 3-dimensional space can be packed with shifted (2, 2, 2)-tripods. de Bruijn
c) Similarly, at least 65/108 of 3D space can be packed with shifted (3, 3, 3)-tripods. bricks
canonical bricks
d) Let r(l,m, n) be the maximum number of pods that can be packed in an l x m x n Hoffman
cuboid. Prove that at least (1+l+m+n)r(l, m, n)/(4lmn) of 3-dimensional space bricks
polysphere
can be packed with shifted (l, m, n)-tripods. face-centered cubic lattice
e) Use Algorithm M to evaluate r(l,m,n) for 4 < l < m < n < 6. cannonballs
oranges
► 347. [M21 ] (N. G. de Bruijn, 1961.) Prove that an l x m x n box can be completely ball-piling
filled with 1 x 1 x k bricks only if k is a divisor of l, m, or n. (Consequently, it can be barycentric coordinates
completely filled with a x b x c bricks only if a, b, and c all satisfy this condition.) close packing of spheres
348. [M41] Find the maximum number of “canonical bricks” (1 x 2 x 4) that can be
packed into an l x m x n box, leaving as few empty cells as possible.
► 349. [M27] (D. Hoffman.) Show that 27 bricks of size a x b x c can always be packed
into an s x s x s cube, where s = a + b + c. But if s/4 < a < b < c, 28 bricks won’t fit.
350. [22] Can 28 bricks of size 3 x 4 x 5 be packed into a 12 x 12 x 12 cube?
351. [M46] Can 55 hypercuboids of size a x b x c x d x e always be packed into a
5-dimensional hypercube of size (a + b + c + d + e) x • • • x (a + b + c + d + e)?
352. [21] In how many ways can the 12 pentominoes be packed into a 2 x 2 x 3 x 5 box?
353. [20] A weak polycube is a set of cubies that are loosely connected via common
edges, not necessarily via common faces. In other words, we consider cubies to be
adjacent when their centers are at most 2 units apart; up to 18 neighbors are possible.
Find all the weak polycubes of size 3, and pack them into a symmetrical container.
► 354. [M30] A polysphere is a connected set of spherical cells that belong to the “face
centered cubic lattice,” which is one of the two principal ways to pack cannonballs (or
oranges) with maximum efficiency. That lattice is conveniently regarded as the set S
of all quadruples (w, x, y, z) of integers for which w + x + y + z = 0. Each cell of S has
12 neighbors, obtained by adding 1 to one coordinate and subtracting 1 from another.
It’s instructive to view S in two different ways, by slicing it into plane layers that
either have constant x+y+z (hence constant w) or constant y+z (hence constant w+x):
x+y+z=4 y+z=4
(Here wy xz stands for (w, x, y, z).) If we include the layers above and below, we get
x+y+z = 5 y+z=5
x+y+z=4 y+z=4
x+y+z=3 y+z=3
with each sphere nestling in the gap between the three or four spheres below it. In
the “hex layers” on the left, (w, x, y, z) lies directly above (w + 3, x - 1, y - 1, z - 1),
July 26, 2019
7.2.2.1 dancing links: exercises—second set 105
but doesn’t touch it; in the “quad layers” on the right, (w, x, y, z) lies directly above planar polysphere
(w + 1, x + 1, y - 1, z - 1), but doesn’t touch it. base placement
rotation
a) Show that every polyomino, and every polyhex, may be regarded as a polysphere: chiral
orthogonal 4 x 4 matrix
base placements
«—> trispheres
tromino
trihexes
b) Conversely, every planar polysphere looks like either a polyomino or a polyhex. anthracene
c) Every polysphere {(w1 , x1, y1 , z1), . . . , (wn, xn, yn, zn)} has a unique base place- phenanthrene
J" ( phenalene
ment { ■«I'i't' qinолЯ hv
(wn , xn , qy/n , znA)}"L /'obtained
(w1 , x1 , y1 , zd1 A), . . . , ( by ciiTdi-*то */■+■ in<t ((w
subtracting QtS , x , о/
y , zd A) SGB graph
from each (wk, Xk, yk, Zk), where x = min{xi,..., xn}, y' = min{yi,...,yn}, simplex
zZ = min{z1,... , zn}, and w' + x + y' + zZ = 0. Prove that x'k + y'k + Zk < n. connected subsets
tetraspheres
d) As with polycubes, we say that polyspheres v and v' are equivalent if the base pyramid
placement of v is also a base placement of some rotation of v' in three dimensions. tetrahedron
roof
(Reflections of “chiral” polyspheres are not considered to be equivalent.) Formally tetraspheres
speaking, a rotation of S about a line through the origin is an orthogonal 4 x 4
matrix that has determinant 1 and preserves w + x + y + z. Find such matrices
for (i) rotation of the hex layers by 120°; (ii) rotation of the quad layers by 90°.
e) A planar polysphere is equivalent to its reflection, because we can rotate by 180°
around a line in its plane. Find suitable 4 x 4 matrices by which we can legally
reflect polyspheres that are equivalent to (i) polyominoes; (ii) polyhexes.
f) Prove that every rotation that takes a polysphere into another polysphere is
obtainable as a product of the matrices exhibited in (d) and (e).
355. [25] The theory in exercise 354 allows us to represent polysphere cells with three
integer coordinates xyz, because x, y , and z are nonnegative in base placements. The
other variable, w, is redundant (but worth keeping in mind); it always equals -x-y - z.
a) What’s a good way to find all the base placements of a given polysphere {xiyizi ,
x2y2z2 , . . . , xnynzn }? Hint: Use exercise 354 to tweak the method of exercise 324.
b) Any three points of three-dimensional space lie in a plane. So exercise 354(b) tells
us that there are just four trispheres: a tromino, two trihexes, and one that’s both:
bent trisphere straight trisphere phenalene phenanthrene
(anthracene)
c) The 4-pyramid and the stretched 4-pyramid involve 30 spheres. What multisets trispheres
of ten trispheres are able to make them? truncated octahedron
permutations
d) The truncated octahedron that represents all permutations of {1, 2, 3, 4} is a polysplatts
noteworthy 24-cell subset of S (see exercise 5.1.1-10). What multisets of six polyhexaspheres
hexagonal close packing
tetraspheres can build it? Baxter
357. [M40] Investigate “polysplatts,” which are the sets of truncated octahedra that Square Dissection
rectangles into rectangles
can be built by pasting adjacent faces together (either square or hexagonal). Mondrian
358. [HM41 ] Investigate “polyhexaspheres,” which are the connected sets of spheres in reduction
strictly reduced
the hexagonal close packing. (This packing differs from that of exercise 354 because each faultfree
sphere of a hexagonal layer is directly above a sphere that’s 2, not 3, layers below it.) trominoes
straight trominoes: 1 X 3
359. [29] Nick Baxter devised an innocuous-looking but maddeningly difficult “Square Motley dissections
Dissection” puzzle for the International Puzzle Party in 2014, asking that the nine pieces dissection: decomposition of one structure i
Thus no two subrectangles are cut off by the same pair of horizontal or vertical lines. pinwheels
The smallest such “motley dissections” are the 3 x 3 pinwheels, Щ and Щ, which are rotations and reflections
symmetric under 180° rotation
considered to be essentially the same because they are mirror images of each other. symmetry
There are eight essentially distinct motley rectangles of size 4 x n, namely order
Postl
f
-1, if i is the final vertex of arc k; for 0 < i < m, 0 < k < r.
0, otherwise;
Similarly, let H be a digraph on the vertices {0, 1, . . . , n}, with arcs defined by the
(n+1) xr incidence matrix B = (bjk). We say that G and H are orthogonal if (i) ai•bj =
0 for 0 < i < m and 0 < j < n; (ii) G and H are connected; and (iii) r = m + n.
July 26, 2019
108 combinatorial searching (f5c: 26 Jul 2019 @ 2051) 7.2.2.1
find the smallest possible squares that have incomparable dissections in integers. Hint: concatenated
Show that there are 2t potential ways to mix the h’s with the w’s, preserving their finite basis theorem
Q pentomino
order; and find the smallest perimeter for each of those cases. Y pentomino
disconnected
► 376. [M25] Find seven different rectangles of area 1/7 that can be assembled into a subcuboids
square of area 1, and prove that the answer is unique. Kim
Postl
377. [M28] Two rectangles of shapes h x w and h' x w' can be concatenated to form nesting
a larger rectangle of size (h + h) x w if w = w', or of size h x (w + w') if h = h'. primitive
a) Given a set S of rectangle shapes, let A(S) be the set of all shapes that can be
made from the elements of S by repeated concatenation. Describe Л({1 x2,3x1}).
b) Find the smallest S C T such that T С Л(5), where T = {hxw | 1 < h < w}.
c) What’s the smallest S with Л^) = { hxw | h, w > 1 and hw mod 8 = 0}?
d) Given m and n, solve (c) with Л^) = { hxw | h, w > m and hw mod n = 0}.
► 378. [M30] (A finite basis theorem.') Continuing exercise 377, prove that any set T of
rectangular shapes contains a finite subset S such that T C Л^).
► 379. [23] What h x w rectangles can be packed with copies of theQ pentomino? Hint:
It suffices to find a finite basis for all such rectangles, using theprevious exercise.
380. [35] Solve exercise 379 for the Y pentomino.
381. [20] Show that 3n copies of the disconnected shape ‘ ’ can pack a
12 x n rectangle for all sufficiently large values of n.
► 382. [18] There’s a natural way to extend the idea of motley dissection to three dimen
sions, by subdividing an l x m x n cuboid into subcuboids [ai . . bi) x [ci . . di) x [ei . . fi)
that have no repeated intervals [ai.. bi) or [ci.. di) or [ei.. fi).
For example, Scott Kim has discovered a remarkable motley
7 x 7 x 7 cube consisting of 23 individual blocks, 11 of which are
illustrated here. (Two of them are hidden behind the others.) The I
full cube is obtained by suitably placing a mirror image of these [ I si/Ji I
pieces in front, together with a 1 x 1 x 1 cubie in the center. I
By studying this picture, show that Kim’s construction can
be defined by coordinate intervals [ai.. bi) x [ci.. di) x [ei.. fi), with
0 < ai, bi, ci, di, ei, fi < 7 for 1 < i < 23, in such a way that the pattern is symmetrical
under the transformation xyz ^ yzx. In other words, if [a .. b) x [c.. d) x [e. .f) is one
of the subcuboids, so is [7 - d . . 7 - c) x [7 - f . . 7 - e) x [7 - b . . 7 - a).
383. [29] Use exercise 382 to construct a perfectly decomposed 92 x 92 x 92 cube,
consisting of 23 subcuboids that have 69 distinct integer dimensions. (See exercise 373.)
384. [24] By generalizing exercises 365 and 366, explain how to find every motley
dissection of an l x m x n cuboid, using Algorithm M. Note: In three dimensions, the
strictness condition ‘(ai, bi) = (0, m) and (ci, di) = (0, n)’ of exercise 362 should become
[(ai, bi) = (0, l)] + [(ci, di) = (0, m)] + [(ei, fi) = (0, n)] < 1.
► 386. [M34 ] A polyomino can have eight different types of symmetry: polyomino
8-fold symmetry
(i) (ii) (iii) (iv) (v) (vi) (vii) (viii) central symmetry
left-right symmetry
4^;
□; ^7^; □; ■ 1 j.
biaxial
bidiagonal
axial
full 90o 180o biaxial bidiagonal axial diagonal none 90o
180o
bilateral symmetry, see biaxial
(Case (i) is often called 8-fold symmetry; case (iii) is often called central symmetry; symmetry types
case (vi) is often called left-right symmetry. Cases (ii), (iv), (v) are 4-fold symmetries; polyiamond
cases (ii) and (iii) are rotation symmetries; cases (iv)-(vii) are reflection symmetries.) polyhex
polycube
In each case an n-omino of that symmetry type has been shown, where n is minimum. logic puzzles
How many symmetry types can a polyiamond or polyhex have? Give example futoshiki
kenken
n-iamonds and n-hexes of each type, where n is minimum.
masyu
► 387. [M36] Continuing exercise 386, how many symmetry types can a polycube have? slitherlink
kakuro
Give an example of each type, using the minimum number of cubies. sudoku
futoshiki
latin square
EXERCISES — Third Set strong clue
weak clue
The following exercises are based on several intriguing logic puzzles that have recently pi as source
become popular: futoshiki, kenken, masyu, slitherlink, kakuro, etc. Like sudoku, these sudoku
lower and upper bounds
puzzles typically involve a hidden pattern, for which only partial information has been bounds
revealed. The point of each exercise is usually to set up an appropriate exact cover exact cover problem
problem, and to use it either to solve such a puzzle or to create new ones. pairwise ordering trick
color controls
► 388. [21 ] The goal of a futoshiki puzzle is to deduce the entries of a secret latin square, XCC problem
valid
given only two kinds of hints: A “strong clue” is an explicit entry; a “weak clue” is a
greater-than relation between neighboring entries. The entries are the numbers 1 to n,
where n is usually 5 as in the following examples:
□ □ □ □ □ □>□ □ □ [2 [3 □ □ □<□
□>□ □>□ □ □ □ □ □ □
a) □ □□ □ □; b) □ □ <□>□ □; c) □ □ [4 □ □.
□ □<□ □ □ □ □ □ □ □
□<□ □ □ □ □ E<D □ □ □ □<□ □ [5
Solve these puzzles by hand, using sudoku-like principles.
389. [20] Sketch a simple algorithm that finds simple lower and upper bounds for each
entry that is part of a weak clue in a futoshiki puzzle, by repeatedly using the rule that
a < x < У < b implies x < b — 1 and y > a + 1. (Your algorithm shouldn’t attempt to
give the best possible bounds; that would solve the puzzle! But it should deduce the
values of five entries in puzzle (a) of exercise 388, as well as entry (4, 2) of puzzle (b).)
► 390. [21 ] Show that every futoshiki puzzle is a special case of an exact cover problem.
In fact, show that every such puzzle can be formulated in at least two different ways:
a) Use a pairwise ordering trick analogous to (25) or (26), to encode the weak clues.
b) Use color controls to formulate an XCC problem suitable for Algorithm C.
391. [20] A futoshiki puzzle is said to be valid if it has exactly one solution. Use
Algorithm X to generate all possible 5 x 5 latin squares. Explain why many of them
can’t be the solution to a valid futoshiki puzzle unless it has at least one strong clue.
July 26, 2019
7.2.2.1 dancing links: exercises—third set 111
► 392. [25] There are 26 (460) = 245656320 ways to construct a 5 x 5 futoshiki puzzle pi
that has six weak clues and no strong ones. How many of them (a) are valid? (b) have Save the sheep
sheep
no solutions? (c) have more than one solution? Also refine those counts, by considering fence
how many such puzzles of types (a), (b), and (c) have at least one “long path” p < q < XCC
KenKen®
r < s < t (like the path that’s present in exercise 388(a)). Give an example of each case.
cages
393. [25] There are 56 265 = 2767187500 ways to construct a 5 x 5 futoshiki puzzle pi, as source
that has six strong clues and no weak ones. How many of them (a) are valid? (b) have
no solutions? (c) have more than one solution? Give an example of each case.
394. [29] Show that every 5x5 futoshiki puzzle that has only five clues — strong, weak,
or a mixture of both — has at least four solutions. Which puzzles attain this minimum?
395. [25] Continuing exercise 391, find a 5 x 5 latin square that cannot be the solution
to a valid futoshiki puzzle unless at least three strong clues have been given.
► 396. [25] Inspired by exercise 388(c), construct a valid 9 x 9 futoshiki puzzle whose
diagonal contains the strong clues (3, 1, 4, 1, 5, 9, 2, 6, 5) in that order. Every other clue
should be a weak ‘<’ — not a ‘>’, not a ‘Л’, not a ‘V’.
► 397. [30] (Save the sheep.) Given a grid in which some of the cells are occupied by
sheep, the object of this puzzle is to construct a fence that keeps all the sheep on one
side. The fence must begin and end at the edge of the grid, and it must follow the grid
lines without visiting any point twice. Furthermore, exactly two edges of each sheep’s
square should be part of the fence. For example, consider the following 5 x 5 grids:
The four sheep on the left can be “saved” only with the fence shown in the middle.
Once you understand why, you’ll be ready to save the four sheep on the right.
a) Explain how Algorithm C can help to solve puzzles like this, by showing that
every solution satisfies a certain XCC problem. Hint: Imagine “coloring” each
square with 0 or 1, with 1 indicating the cells on the sheep’s side of the fence.
b) Devise an interesting 8 x 8 puzzle that has a unique solution and at most 10 sheep.
398. [23] (KenKen1®.) A secret latin square whose entries are {1, 2,... ,n} can often
be deduced by means of arithmetic. A kenken puzzle specifies the sum, difference,
product, or quotient of the entries in each of its “cages,” which are groups of cells
indicated by heavy lines, as in the following examples:
(When the operation is ‘—’ or ‘^’, the cage must have just two cells. A one-cell cage
simply states its contents, without any operation; hence its solution is a no-brainer.)
Cages look rather like the boxes of jigsaw sudoku (see (34)); but in fact the
rules are quite different: Two entries of the same cage can be equal, if they belong to
July 26, 2019
112 combinatorial searching (f5c: 26 Jul 2019 @ 2051) 7.2.2.1
different rows and different columns. For example, the ‘9x’ in (a) can be achieved only valid
by multiplying the three entries {1, 3, 3}; hence there’s exactly one way to fill that cage. hexadecimal digits
pentominoes
Solve (a), (b), (c) by hand. Show that one of them is actually not a valid puzzle. names of pentominoes
П
► 399. [22] How can all solutions to a kenken puzzle be obtained with Algorithm C? Hidato1®
400. [21 ] Many clues of a kenken puzzle often turn out to be redundant, in the sense Hamiltonian path
king moves
that the contents of one cage might be fully determined by the clues from other cages. 8-neighbors, see King neighbors
For example, it turns out that any one of the clues in puzzle 398(a) could actually be pi, as “random”
omitted, without permitting a new solution.
Find all subsets of those 11 clues that suffice to determine a unique latin square.
401. [22] Find all 4 x 4 kenken puzzles whose unique solution is the latin 1234
2143
square shown at the right, and whose cages all have two cells. Furthermore, 4312
there should be exactly two cages for each of the four operations +, —, x, ^. 3421
402. [24] Solve this 12 x 12 kenken puzzle, using hexadecimal digits from 1 to C:
The five-cell cages of this puzzle have O P 2- Q
multiplicative clues, associated with 15 + 11 + 1- 1- 7+
the names of the twelve pentominoes:
3- 8- 16 + 1- T
O, 9240x R 5- S 21 + 8-
P, 5184 x V~~
1- 7-
Q, 3168x
W
R, 720x 4- 15 + 11 + 4-
S, 15840x 3- 8- 8+ 4- 2-
T, 19800x U 13 + 16 + 7- 1-
U, 10560x 2- 1- Y 2- 2-
8+
V, 4032x
X Z
W, 1620x 3- 14 + 14 +
X, 5040x 3- 13 + 5-
Y, 576x 4- 10- 3-
Z, 17248x
► 403. [31 ] Inspired by exercises 398(a) and 398(c), construct a valid 9x9 kenken puzzle
whose clues exactly match the decimal digits of n, for as many places as you can.
► 404. [25] (Hidato®.) A “hidato solution” is an m x n matrix whose entries are a
permutation of {1, 2, . . . , mn} for which the cells containing k and k + 1 are next to
each other, either horizontally, vertically, or diagonally, for 1 < k < mn. (In other
words, it specifies a Hamiltonian path of king moves on an m x n board.) A “hidato
puzzle” is a subset of those numbers, which uniquely determines the others; the solver
is supposed to recreate the entire path from the given clues.
3 14 1 3 14 1 3 14 1 16 3 14 1
4 2 4 2 4 15 2 13
5 9 5 9 5 9 5 9 10 12
8 8 6 8 6 7 8 11
(i) (ii) (iii) (iv)
For example, consider the 4 x 4 puzzle (i). There’s only one place to put ‘2’. Then
there are two choices for ‘4’; but one of them blocks the upper left corner (see (ii)), so
we must choose the other. Similarly, ‘6’ must not block any corner. Therefore (iii) is
forced; and it’s easy to fill in all of the remaining blanks, thereby obtaining solution (iv).
Explain how to encode such puzzles for solution by Algorithm C.
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—THIRD SET 113
405. [21 ] The preceding exercise needs a subroutine to determine the endpoints of all simple paths
simple paths of lengths 1, 2, . . . , L from a given vertex v in a given graph. That problem NP-hard
Beluhov
is NP-hard; but sketch an algorithm that works well for small L in small graphs. П
Slitherlink
406. [16] Show that the following hidato puzzle isn’t as hard as it might look at first: closed paths
loops
19 52 53 54 4 62 63 64 cycles
20 1 rectangular grid
dead end
21 60
41 59
31 58
32 9
33 10
35 34 37 28 27 26 11 12
► 407. [20] Here’s a curious 4 x 8 array that is consistent with 52 hidato solutions:
Some experimentation now tells us which edge must go with the lower 1. We must not
form two loops, as in (iii) or (iv). And hurrah: There’s a unique solution, (v).
Which of the following 5 x 5 slitherlink diagrams are valid puzzles? Solve them.
0 0 0 1 11 2 2 2 3 3 3
0 0 11 2 2 3 3
(a) 0 0 ; (b) 1 1 ; (c) > 2 ; (d) 3 3.
0 0 11 2 2 3 3
0 0 0 1 11 2 2 2 3 3 3
411. [20] True or false: A slitherlink diagram with a numeric clue given in every cell
always has at most one solution. Hint: Consider the 2 x 2 case.
July 26, 2019
114 combinatorial searching (f5c: 26 Jul 2019 @ 2051) 7.2.2.1
► 412. [22] A “weak solution” to a slitherlink diagram is a set of edges that obeys the weak solution
numeric constraints, and touches every vertex of the grid either twice or not at all; but two-factor, induced
XCC problem
it may form arbitrarily many loops. For example, the diagram of exercise 410(i) has tiles
six weak solutions, three of which are shown in 410(iii), (iv), and (v). even/odd coordinates
masyu
Show that there’s a nice way to obtain all the weak solutions of a given diagram, homogeneous
by formulating a suitable XCC problem. Hint: Think of the edges as constructed from redundant clues
tiles centered at the vertices, and use even/odd coordinates as in answer 133. Beluhov
symmetrical puzzles
► 413. [30] Explain how to modify Algorithm C so that the construction of exercise 412 surprise
will produce only the true “single-loop” solutions. Your modified algorithm shouldn’t
be specific to slitherlink; it should apply also to masyu and other loop-discovery puzzles.
414. [25] The “strongest possible” answer to exercise 413 would cause the.............
modified Algorithm C to backtrack as soon as the current choice of edge colors .1.0. . . .
is incompatible with any single loop. Show that the algorithm in that answer is ■ 2 ^-q-
not as strong as possible, by examining its behavior on the puzzle at the right. ................
► 415. [M33] Exactly 5 • (225 — 1) nonempty slitherlink diagrams of size 5 x 5 are “homo
geneous,” in the sense that all of their clues involve the same digit d G {0,1, 2, 3,4}.
(See exercise 410(a)-(d).) How many of them are valid puzzles? What are the minimum
and maximum number of clues, for each d, in puzzles that contain no redundant clues?
416. [M30] For each d G {0, 1, 2, 3, 4}, construct valid n x n slitherlink diagrams whose
nonblank clues are all equal to d, for infinitely many n.
417. [M46] (N. Beluhov, 2018.) Exercise 410(a, b, d) illustrates three homogeneous
slitherlink puzzles that are valid for exactly the same pattern of nonblank clues. Do
infinitely many such square puzzles exist?
418. [M29] An m x n slitherlink diagram is said to be symmetrical if cells (i, j) and
(m — 1 — i, n — 1 — j) are both blank or both nonblank, for 0 < i < m and 0 < j < n.
(Many grid-based puzzles obey this oft-unwritten rule.)
a) There are exactly 625 ~ 2.8 x 1019 slitherlink diagrams of size 5 x 5, since each
of the 25 cells can contain either ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, or ‘ ’. How many of those
diagrams are symmetrical?
b) How many of the symmetric diagrams in (a) are valid puzzles?
c) How many of those valid puzzles are minimal, in the sense that the deletion of
nonblank clues in (i, j) and (4 — i, 4 — j) would make the solution nonunique?
d) What is the minimum number of clues in a valid 5 x 5 symmetrical puzzle?
e) What is the maximum number of clues in a minimal 5 x 5 symmetrical puzzle?
419. [30] What surprise is concealed in the following symmetrical slitherlink puzzle?
. . .^ .^ .^ .1. . . .
2 0 1 0 1 12
21 212111
2 2 2 2 1 1 2
300 2 120000
...... 1’ ’ 1 ’0’ ’ T ’0’ ’ ’ ’
......... 2,0, .1 .1.1.0......
................211 '0 4’1......................
' ' ■ T T ’ ’0’ T ’ '0......
0021 10 1 000
................... 2 '0 4'1'^ ’ '0 '0'
021101 10
'0'1" ТГ ’ ’ '1'1...... 0’ ’ ’
110 12 10
July 26, 2019
7.2.2.1 dancing links: exercises—third set 115
420. [M22] Consider an m x n slitherlink with m and n odd, having 2s in the pattern Masyu
XCC problem
'2. '2. '2. '2. '2. '2. '2. minimal
Y Y '2. ;2 ;2 Y
;/ Л '2\ '2\ '2\ 22
(and possibly other clues). Show that there’s no solution if m mod 4 = n mod 4 = 1.
► 421. [20] (Masyu.) A masyu (“evil influence”) puzzle, like slitherlink, conceals a
hidden loop of straight segments. But there are two imp ortant differences. First, the
loop passes through the centers of grid cells, instead of following the edges. Second,
no numerical quantities are involved; the clues are entirely visual and geometrical.
Clues appear in circles through which the loop must pass: (i) The path must turn
90° at every black circle; but it must travel straight through the two neighboring cells
just before and after turning. (ii) The path must not turn 90° when it goes through
a white circle; and it must not travel straight through the two neighboring cells just
before and after not turning. (Thus it must actually turn, at one or both of those cells.
We get at least one turn per clue, and at least one straight segment.)
Consider, for example, a 5 x 5 puzzle with a black clue in cell 02, and
with white clues in cells 13, 30, 32, and 43 as shown. The loop clearly will
have to include the subpaths 20 --- 30 --- 40 --- 41 and 42 --- 43 --- 44 --- 34
in some order. It also must include either 00 --- 01 --- 02 --- 12 --- 22 or 04 --
03 --- 02 --- 12 --- 22, because of the black clue. But the latter alternative is
impossible, because it leaves no way to go straight through the white clue in
13. Thus 10 --- 00 --- 01 --- 02 --- 12 --- 22 is forced; and also 23 --- 13 --
03 --- 04 --- 14 --- 24 --- 34. (We couldn’t go 24 --- 23, because that would
close the loop prematurely.) The rest of the path now sort of falls into place.
Show that one of the clues in this example puzzle is actually redundant. But if
any of the other four clues are absent, show that alternative solutions are possible.
422. [21] Show that the “weak solutions” to any given masyu puzzle are the solutions
to an easily constructed XCC problem, by adapting the solution of exercise 412.
► 423. [M25] For each of the (m-1)n + m(n-1) potential edges e in the solution of an
m x n masyu puzzle, let xe be the boolean variable ‘[e is present]’. The XCC problem
constructed in exercise 422 is essentially a set of constraints on those variables.
Explain how to improve that construction dramatically, by exploiting the follow
ing special property that is enjoyed by masyu puzzles: Let N , S , E , and W be the
edges leading out of a cell that holds a clue. If the clue is black, we have N = -'-S and
E = --W; if the clue is white, we have N = S, E = W, and E = --N. (Thus every
clue reduces the number of independent variables by at least 2.)
► 424. [36] Make an exhaustive study of 6 x 6 masyu, and gather whatever statistics
you think are particularly interesting. For example, how many of the 336 ~ 1.5 x 1017
ways to place white or black clues lead to a valid puzzle? Which of the valid puzzles
have the fewest clues? the most clues? the shortest loops? the longest loops? only
white clues? only black clues? How many of those puzzles are minimal, in the sense
that none of their clues can be removed without allowing a new solution?
How many of the 236 ~ 6.9 x 1010 ways to occupy cells occur as the pattern of
white clues in a valid puzzle? How many of them occur as the pattern of black clues?
How many puzzles remain valid when white and black are interchanged? Which 6 x 6
masyu puzzle do you think is most difficult to solve?
July 26, 2019
116 combinatorial searching (f5c: 26 Jul 2019 @ 2051) 7.2.2.1
425. [28] The solution to a masyu puzzle is composed of five kinds of “tiles”: pi, as random
8-fold symmetry
‘О’, ‘Яг ’, ‘ ’, ‘ ’, and blank. For example, the 3 X 3 solution shown here triangular grid
contains two tiles of each nonblank type. sharp turns
Find 4 X 4, 5 X 5, and 6 X 6 puzzles whose unique solutions have exactly k tiles slack turns
triangular masyu
of each nonblank type, for every possible k. pi, as random
► 426. [31 ] Obtain a valid masyu puzzle from diagram (i) below by changing each ‘O’ homogeneous
Kakuro
clue into either ‘O’ or ‘®’. crossword puzzle
blocks
ordered partitions into distinct parts
(i)
► 427. [25] Design a 25 X 25 masyu puzzle by adding white clues (only) to diagram (ii)
above. All of your clues should preserve the 8-fold symmetry of this pattern.
428. [M28] For infinitely many n, construct a valid nXn masyu puzzle with O(n) clues
whose loop goes through all four corner cells, where all clues are (a) black; (b) white.
429. [21] A closed path on a triangular grid may have “sharp turns,” which change
the direction by 120°, or “slack turns,” which change the direction by 60°, or both.
Therefore triangular masyu has three flavors of clues: ‘>’ for the sharp turns, ‘O’ for
the slack turns, and of course ‘O’ for the non-turns.
a) Solve the following homogeneous triangular masyu puzzles:
b) The following patterns for triangular masyu are clearly impossible to solve. But
show that each of them is solvable if the colors { О , О, • } are suitably permuted:
► 430. [26] (Kakuro.') A kakuro puzzle is like a crossword puzzle, except that its “words”
are blocks of two or more nonzero digits {1, 2, . . . , 9}, not strings of letters. The digits
of each block must be distinct, and their sum is given as a clue. Every cell to be filled
belongs to exactly one horizontal block and one vertical block.
For example, the mini-kakuro shown here has just three horizontal
blocks and three vertical blocks. Notice that the desired sums are indicated
to the immediate left or above each block; thus the first horizontal block
is supposed to be filled with two digits that sum to 5, so there are four
possibilities: 14, 23, 32, 41. The first vertical block should sum to 6;
again there are four possibilities, this time 15, 24, 42, 51 (because 33 is
forbidden). The second horizontal block has three digits that should sum to 19; it
is considerably less constrained. Indeed, there are thirty ways to obtain 19-in-three,
namely the permutations of {2, 8, 9} or {3, 7, 9} or {4, 6, 9} or {4, 7, 8} or {5, 6, 8}.
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—THIRD SET 117
a) Solve the puzzle. Hint: There’s only one possibility for the lower right corner. combinations
b) Sketch a simple way to build a table of all suitable combinations of n-in-k, for bitmaps
Generalized kakuro
2 < k < 9 and 2 < n < 45. Which n and k have the most? Hint: Use bitmaps. word squares
c) Generalized kakuro is a related puzzle, for which each block of length k has a efficient: reasonably fast
Funk
specified set of combinations, chosen from among the k9 possibilities (regardless
Cross Sums
of their sum). For example, suppose the three horizontal blocks of mini-kakuro
must be filled respectively with permutations of {1, 3}, {3, 5}, or {5, 7}; {1, 3, 5},
{1, 7, 9}, {2, 4, 6}, {6, 8, 9}, or {7, 8, 9}; {2, 4}, {4, 6}, or {6, 8}; and require the
same for the three vertical blocks. Find the unique solution to that puzzle.
d) It would be easy to formulate kakuro as an XCC problem, as we did word squares
in exercise 87, by simply giving one option for each possible placement of a block.
But the resulting problem might be gigantic: For example, long blocks are not
uncommon in kakuro, and each 9-digit block would have 9! = 362,880 options(!).
Show that generalized kakuro can be formulated efficiently as an XCC problem.
► 431. [30] The inventor of kakuro, Jacob E. Funk of Manitoba (who always called his
puzzles “Cross Sums”), published the following challenge on pages 50 and 66 of the
August/September 1950 issue of Dell Official Crossword Puzzles:
Many ingenious constructions are present here; but unfortunately, he failed to realize
that there is more than one solution. Find all solutions, and obtain a valid puzzle by
repairing some of his original clues.
► 432. [M25] We can’t simply design new kakuro puzzles by randomly filling the blanks
and using the resulting sums as the constraints, because the vast majority of feasible
sums yield nonunique solutions. Verify this exp erimentally for the generic diagrams
digits in any row or column, as well as exactly how many of those filled-in diagrams
are uniquely reconstructible from their block sums. Consider also symmetry.
July 26, 2019
118 combinatorial searching (f5c: 26 Jul 2019 @ 2051) 7.2.2.1
433. [26] Six of the sum-clues in this little kakuro diagram are unspecified: n
Hitori
word rectangle
seeds
articulation points
weak solution
In how many ways can you obtain valid puzzles by specifying them?
434. [30] Exactly how many kakuro diagrams are possible in a 9 x 9 grid? (Every row
and every column should contain at least one block of empty cells, except that the top
most row and leftmost column are completely black. All blocks must have length > 2.
Empty cells needn’t be rookwise connected.) What is the maximum number of blocks?
435. [31 ] Design a rectangular kakuro puzzle for which the blocks at the top of the
solution are 31, 41, 59, 26, 53, 58, 97 (the first fourteen digits of n).
► 436. [20] (Hitori.) Let’s wind up this potpourri of examples by considering a com
pletely different combinatorial challenge. A hitori puzzle (“alone”) is an m x n array
in which we’re supposed to cross elements out until three conditions are achieved:
i) No row or column contains repeated elements.
ii) Adjacent elements cannot be crossed out.
iii) The remaining elements are rookwise connected.
For example, consider the 4 x 5 word rectangle (a). Conditions (i) and (ii) can
be satisfied in sixteen ways, such as (в) and (y). But only (5) satisfies also (iii).
(a) (в) (y) (5)
S K i F F s k iHf K iF KiF
i N N E R iMn e r E R
T i T L E iч l]e i T E I _t
S T O L E STOLE STOL SIT OIL
A crossed-out cell is said to be black; the other cells are white. While solving a
hitori, it’s helpful to circle an entry that is certain to become white. We can initially
circle all the “seeds” — the entries that don’t match any others in their row or column.
For example, puzzle (a) has eight seeds. If we decide to blacken a cell,
S KI F F
we immediately circle its neighbors (because they cannot also be black). Thus, I N N E R
for instance, we shouldn’t cross out the E in cell (2, 4): That would circle the L T I T L E
in (2, 3), forcing the other L to be black and cutting off the corner E as in (в). S T O L E
The precise value of a seed is immaterial to the puzzle; it can be replaced by any
other symbol that differs from everything else in its row or column.
We say as usual that a hitori puzzle is valid if it has exactly one solution. Explain
why (a) a valid hitori puzzle has exactly one solution with all seeds white; (b) a hitori
puzzle that has a unique solution with all seeds white is valid if and only if all the seed
cells not adjacent to black in that solution are “articulation points” for the set of white
cells — that is, their removal would disconnect the whites. (See (3, 1) and (3, 2) in (5).)
► 437. [21 ] A weak solution to a hitori puzzle is a solution for which all seeds are white,
and for which properties (i) and (ii) of exercise 436 hold. Given a hitori puzzle, define
an XCC problem whose solutions are precisely its weak solutions.
July 26, 2019
7.2.2.1 DANCING LINKS: EXERCISES—THIRD SET 119
438. [30] Explain how to modify Algorithm C so that, when given an XCC problem modify Algorithm C
from the construction in answer 437, it will produce only solutions that satisfy also the reachability
hitori cover
connectivity condition (iii). Hint: See exercise 413; also consider reachability. seedless hitori puzzles
439. [M20] Let G be a graph on the vertices V. A hitori cover of G is a set U С V e
de Ruiter
such that (i) G | U is connected; (ii) if v / U and u — v then u U U; (iii) if u U U and П
if v U U for all u — v, then G | (U \ u) is not connected. double word squares
WORDS(3000)
a) Describe a hitori cover in terms of standard graph theory terminology. de Ruiter
b) Show that the solution of a valid hitori puzzle is a hitori cover of Pm Pn . Orwell
Homer
440. [21 ] True or false: If the letter A occurs exactly twice in the top row of a valid Shakespeare
hitori puzzle, exactly one of those occurrences will survive in the solution. Tolstoy
441. [18] Describe every valid hitori puzzle of size 1 x n on a d-letter alphabet.
► 442. [M33] Enumerate all hitori covers of Pm □ Pn, for 1 < m < n < 9.
► 443. [M30] Prove that an m x n hitori cover has at most (mn + 2)/3 black cells.
444. [M27] Can a valid n x n hitori puzzle involve fewer than 2n/3 distinct elements?
Construct a valid puzzle of size 3k x 3k, using only the elements {0, 1, . . . , 2k}.
► 445. [M22] It’s surprisingly difficult to construct a valid hitori puzzle that has no
seeds. In fact, there are no n x n examples for n < 9 except when n = 6. But it turns
out that quite a few seedless 6 x 6 hitori puzzles do exist.
Consider the five hitori covers below. Determine, for each of them, the exact
number of valid hitori puzzles with no seeds, having that pattern of white and black
cells as the solution. Hint: In some cases the answer is zero.
► 446. [24] The digits of e, 2.718281828459045. .. , are well known to have a curious
repeating pattern. In fact, the first 25 digits actually define a valid 5 x 5 hitori puzzle!
What is the probability that a random 5 x 5 array of decimal digits will have that
property? And what about octal digits? Hexadecimal digits?
447. [22] (Johan de Ruiter.) Are there any values of m > 1 and n > 1 for which the
first mn digits of n define a valid m x n hitori puzzle?
448. [22] Do any of the 31344 double word squares formed from words(3000) make
valid hitori puzzles? (See exercise 87.)
449. [40] (Hidden nuggets.) Johan de Ruiter noticed in 2017 that George Orwell had
included a valid hitori puzzle in his novel Nineteen Eighty-Four (part 2, chapter 9):
B E I N G I N A M I
N O R I T Y E V E N
A M I N O R I T Y O
F O N E D I D N O T
M A K E Y O U M A D
Did Homer, Shakespeare, Tolstoy, and others also create hitori puzzles accidentally?
I1. [Read the first line.] Set N1 <-- 1, i ^ 0. Then, for each item name a on the first secondary items, list of active
line, set i ^ i + 1, NAME(i) ^ a, LLINK(i) ^ i — 1, RLINK(i — 1) ^ i. If a names spacer
nonsharp preference
the first secondary item, also set N1 ^ i — 1. (In practice a is limited to at most 8
characters, say. One should report an error if a = name(j) for some j < i.)
I2. [Finish the horizontal list.] Set N ^ i. If N1 < 0 (there were no secondary items),
set Ni ^ N. Then set LLINK(N +1) ^ N, RLINK(N) ^ N +1, LLINK(Ni + 1) ^
N +1, RLINK(N +1) ^ Ni + 1, LLINK(0) ^ Ni, RLINK(Ni) ^ 0. (The active
secondary items, if any, are accessible from record N + 1.)
I3. [Prepare for options.] Set LEN(i) ^ 0 and ULINK(i) ^ DLINK(i) ^ i for 1 < i < N.
(These are the header nodes for the N item lists, which are initially empty.) Then
set M ^ 0, p ^ N +1, TOP(p) ^ 0. (Node p is the first spacer.)
I4. [Read an option.] Terminate with Z ^ p if no input remains. Otherwise let the next
line of input contain the item names ai . . . ak , and do the following for 1 < j < k:
Use an algorithm from Chapter 6 to find the index ij for which name(ij ) = aj .
(Report an error if unsuccessful. Complain also if an item name appears more
than once in the same option, because a duplicate might make Algorithm X fail
spectacularly.) Set LEN(ij) ^ LEN(ij) +1, q ^ ULINK(ij), ULINK(p + j) ^ q,
DLINK(q) ^ p + j, DLINK(p + j) ^ ij, ULINK(ij) ^ p + j, TOP(p + j) ^ ij.
I5. [Finish an option.] Set M ^ M+1, DLINK(p) ^ p+k, p ^ p+k+1, TOP(p) <-- M,
ULINK(p) ^ p — k, and return to step I4. (Node p is the next spacer.) |
9. Set 0 ^ to, p ^ RLINK(0). While p = 0, do the following: Set A ^ LEN(p); if A<0
set 0 ^ A, i ^ p; and set p ^ RLINK(p). (We could exit the loop immediately if 0 = 0.)
10. If LEN(p) > 1 and NAME(p) doesn’t begin with ‘#’, set A ^ M + LEN(p) instead
of len(p). (Similarly, the “nonsharp preference” heuristic favors nonsharp items.)
11. Item a is selected at level 0, trying option x0 = 12, ‘a d g’, and leading to (7). Then
item b is selected at level 1, trying xi = 16, ‘b c f’. Hence, when the remaining item e
is selected at level 2, it has no options in its list, and backtracking becomes necessary.
Here are the current memory contents — substantially changed from Table 1:
i: 0 1 2 3 4 5 6 7
NAME(i): — a b c d e f g
LLINK(i): 0 0 0 0 3 0 5 6
RLINK(i): 0 2 3 5 5 0 0 0
x: 0 1 2 3 4 5 6 7
LEN(x): — 2 1 1 1 0 0 1
ULINK(x): — 20 16 9 27 5 6 25
DLINK(x): — 12 16 9 27 5 6 25
x: 8 9 10 11 12 13 14 15
TOP(x): 0 3 5 -1 1 4 7 -2
ULINK(x): — 3 5 9 1 4 7 12
DLINK(x): 10 3 5 14 20 21 25 18
x: 16 17 18 19 20 21 22 23
TOP(x): 2 3 6 -3 1 4 6 -4
ULINK(x): 2 9 6 16 12 4 18 20
DLINK(x): 2 3 6 22 1 27 6 25
x: 24 25 26 27 28 29 30
TOP(x): 2 7 -5 4 5 7 -6
ULINK(x): 16 7 24 4 10 25 27
DLINK(x): 2 7 29 4 5 7 —
12. Report that x is out of range if x < N or x > Z or TOP(x) < 0. Otherwise set Z
q ^ x and do “print NAME(TOP(q)) and set q ^ q + 1; if TOP(q) < 0 set q ^ ULINK(q)” N
sudoku
until q = x. Then set i ^ TOP(x), q ^ DLINK(i), and k ^ 1. While q = x and q = i, Historical remarks
set q ^ DLINK(q) and k ^ k + 1. If q = i, report that the option containing x is Lucas
Tait
‘k of len(i)’ in item i’s list; otherwise report that it’s not in that list.
Cayley
13. For 0 < j < l, node xj is part of an option in the solution. By setting r ^ xj and Muir
recurrence relation
then r ^ r + 1 until TOP(r) < 0, we’ll know exactly what that option is: It’s option Touchard
number -top(r), which begins at node ulink(r). (Many applications of Algorithm X Kaplansky
asymptotic formula
have a custom-made output routine, to convert x0 . . . xl-1 into an appropriate format — Riordan
presenting it directly as a sudoku solution or a box packing, etc.) Wyman
Exercise 12 explains how to provide further information, not only identifying the Moser
exponential generating function
option of xj but also showing its position in the search tree. generating function
factorial generating function
14. (a) The options are ‘Sj Mk ’, for all 0 < j, k < n except j = k or j = (k + 1) mod n. Flajolet
(b) There are (u3, . . . , u10) = (1, 2, 13, 80, 579, 4738, 43387, 439792) solutions. The Sedgewick
running time for n = 10 is about 180 (or 275) mems per solution with (or without) MRV.
[This problem has a rich history: E. Lucas presented and named it in his Theorie
des Nombres (1891), 215, 491-495. An equivalent problem had, however, already been
posed by P. G. Tait, and solved by A. Cayley and T. Muir; see Trans. Royal Soc.
Edinburgh 28 (1877), 159, and Proc. Royal Soc. Edinburgh 9 (1878), 338-342, 382
391, 11 (1880), 187-190. In particular, Muir found the recurrence relation
where Tn = kn=0(-2)k/k! is the sum of the first n+ 1 terms of the power series for e-2
The menage numbers therefore satisfy the interesting asymptotic formula
for all fixed k > 0, discovered by I. Kaplansky and J. Riordan (Scripta Mathematica
12 (1946), 113-124). In fact, M. Wyman and L. Moser proved that the sum of this
series for 0 < k < n differs from un by less than 1/2 (Canadian J. Math. 10 (1958),
468-480). Among many other things, they also found a (complicated) expression for
the exponential generating function n unzn/n!. The ordinary generating function
^n unzn has the surprisingly nice form ((1 — z)/(1 + z))F(z/(1 + z)2), where F(z) =
52n>0 n!zn; see P. Flajolet and R. Sedgewick, Analytic Combinatorics (2009), 368-372.]
15. Omit the options with i = n - [n even] and j > n/2. MRV heuristic
secondary items, list of active
(Other solutions are possible. For example, we could omit the options with i = 1 second death
and j > n; that would omit n — 1 options instead of only |_n/2_|. However, the suggested bitwise AND
rule turns out to make Algorithm X run about 10% faster.) author
combination generation
16. The two solutions are ‘r1 c2 a3 b-1’ ‘r2 c4 a6 b-2’ ‘r3 c1 a4 b2’ ‘r4 c3 a7 b1’ ‘a2’
‘a5’ ‘a8’ ‘b-3’ ‘b0’ ‘b3’; ‘r1 c3 a4 b-2’ ‘r2 c1 a3 b1’ ‘r3 c4 a7 b-1’ ‘r4 c2 a6 b2’ ‘a2’ ‘a5’ ‘a8’
‘b-3’ ‘b0’ ‘b3’. At the top levels, the MRV heuristic causes Algorithm X to branch first
on the slack variables a2 , a8 , b-3 , and b3 , which each have at most two possibilities.
(And that’s actually a pretty strange way to tackle the four queens problem!)
17. Branch first on r3 , which has four options. If ‘r3 c1 a4 b2’, there’s just one option
for c2 , then c3 , then r2 , so we get the first solution: ‘r3 c1 a4 b2’ ‘r1 c2 a3 b-1’ ‘r4 c3 a7
b1’ ‘r2 c4 a6 b-2’. If ‘r3 c2 a5 b1’, c3 is forced, then r2 can’t be covered. If ‘r3 c3 a6 b0’,
r2 is forced, then c2 can’t be covered. If ‘r3 c4 a7 b-1’, we cruise to the second solution:
‘r3 c4 a7 b-1’ ‘r1 c3 a4 b-2’ ‘r2 c1 a3 b1’ ‘r4 c2 a6 b2’. (And that’s a good way.)
18. ‘c e’ ‘a d f’ ‘b g’ (as before) and ‘b c f’ ‘a d g’ (new).
19. When all primary items have been covered in step X2, accept a solution only if
len(i) = 0 for all of the active secondary items, namely the items accessible from
rlink(N + 1). [This algorithm is called the “second death” method, because it checks
that all of the purely secondary options have been killed off by primary covering.]
20. For 1 < k < m, set t ^ k & (—k); include secondary item yk in option aj for
k < j < min(m, k +1) and in option ej' for k — t < j <k.
Equivalently, to set up option aj, include a and set t ^ j; while t > 0, include
yt and set t ^ t & (t — 1). To set up option ej', include b and set t <-- 1 — j; while
t > —m, include y-t and set t ^ t & (t — 1).
If j > k, options aj and ek both contain yj&-2Lig(j-k)j •
21. The options aij will contain the primary item ai. Simply do k—1 pairwise orderings,
with secondary items yki to ensure that jk < jk+1 . If m is a power of 2, it turns out
that the options for 1 < i < k each have exactly lg m secondary items. For example, if
m = 4 and k > 2, the options aj2 are ‘a2 y11 y21’, ‘a2 y21 y12’, ‘a2 y31 y22’, ‘a2 y32 y22’.
(The author attempted to knock out options for ai with i7 < i — 1 or i7 > i + 1,
by adding additional secondary items, but that turned out to be a bad idea.)
Of course, this method doesn’t compete with the lightning-quick methods for
combination generation in Section 7.2.1.3; for instance, when m = 20 and k = 8 it
needs 1.1 G// to crank out the (287) = 2220075 coverings, about 500 mems per solution.
22. (a) Let n' = [n/2j +1. By rotation and reflection we can assume that the queen in
column n' (the middle column) is in row i and the queen in row n' is in row j, where 1 <
i < j < n7. We obtain a suitable exact cover problem by leaving out the options o(i, j) =
‘ri Cj ai+j bi-j’ for i = j or i + j = n +1; also omit o(i, j) for i > j when j = n'; j > i
when i = n'; and (i, j) = (n7 — 1,n7) or (n7,1). Then include secondary items to force
the pairwise ordering of ak = o(k + 1,n7) and ek = o(n7,k + 2), for 0 < k < m = n' — 2.
(b) Now we assume a queen in (j, j), where 1 < j < n7, and that the queen in row n
is closer to the bottom right corner than the queen in column n. So we omit options
o(i, j) for i + j = n +1 or i = j > n' or (i, j) = (n, 2) or (i, j) = (n — 1, n); we make item
b0 primary; and we let ak = o(n, n — k — 1), ek = o(n — k — 2, n) for 0 < k < m = n — 3.
(c) This time we want queens in (i, i) and (j, n +1 — j) where 1 < i < j < n7. We
promote an+1 and b0 to primary; omit o(i, j) when i = j > n' — 1 or i = n + 1 — j > n' or
(i, j) = (1, n); and let ak = o(k+1, k+1), ek = o(k+2, n— k — 1) for 0 < k < m = n' — 2.
July 26, 2019
124 answers to exercises 7.2.2.1
In case (a) there are (0, 0, 1, 8, 260, 9709, 371590) solutions for n = (5, 7, . . . , 17); pairwise comparisons
Algorithm X handles n = 17 in 3.4 Gj. [In case (b) there are (0, 0, 1, 4, 14, 21, 109, author
asymmetric
500, 2453, 14498, 89639, 568849) for n = (5, 6,..., 16); and n = 16 costs 6.0 Gj. In singly symmetric
case (c), similarly, there are (1, 0, 3, 6, 24, 68, 191, 1180, 5944, 29761, 171778, 1220908) doubly symmetric
solutions; n = 16 costs 5.5 Gj.]
23. (a) Consider the queens in column a of row 1, row b of column n, column c of row n,
and row d of column 1, where x = n +1 — x. (These four queens are distinct, because
no queen is in a corner. Notice also that neither a nor b nor c nor d can equal a.)
Repeated rotations and/or reflections will change these numbers from (a, b, c, d) to
a a a a a a a a
(b, c, d, a), (c, d, a, b), (d, a, b, c), (d , ca, b, aa), (ca, b, aa, d ), (b, aa, d , ca), (aa, d , ca, b).
Those eight 4-tuples are usually distinct, and in such cases we can save a factor of 8
by eliminating all but one of them. There always is a solution with a < b, c, d < a; and
those inequalities can be enforced by doing three simultaneous pairwise comparisons,
between the options for row 1 and the respective options for column n, row n, and
column 1. For example, the options that correspond to a = 1 when n = 16 are ‘r1 c2 a3
b-1’; ‘r2 c16 a18 b-14 x1 x2 x4’; ‘r15 c16 a31 b-1 x1 x2 x4’; ‘r16 c2 a18 b14 y1 y2 y4’; ‘r16 c14
a30 b2 y1 y2 y4’; ‘r2 c1 a3 b1 z1 z2 z4’; ‘r15 c1 a16 b14 z1 z2 z4’. (Here m = n/2— 1 = 7.)
With this change, the number of solutions for n = 16 drops from 454376 to 64374
(ratio ~ 7.06), and the running time drops from 4.3 Gj to 1.2 Gj (ratio ~ 3.68).
[The author experimented with further restrictions, so that solutions were allowed
only if (i) a < b, c, d; (ii) a = b < c, d; (iii) a = b = c < d; (iv) a = b = c = d; (v) a =
c < b, d. Five options were given for each value of a < n/2 — 1, and m was 6 instead
of 7. The number of solutions decreased to 59648; but the running time increased to
1.9 Gj. Thus a point of diminishing returns had been reached. (A completely canonical
reduction would have produced 57188 solutions, with considerable difficulty.)]
(b) This case is almost identical to (a), because the queen in the center vacates
all other diagonal cells. Requiring a < b, c, d < aa reduces the number of solutions for
n = 17 from 4067152 to 577732 (ratio ~ 7.04), and run time to 3.2 Gj (ratio ~ 4.50).
24. We simply combine compatible options into (a) pairs, (b) quadruplets, and force
a queen in the center when n is odd. For example, when n = 4 we replace (23) by
(a) ‘r1 c2 a3 b-1 r4 c3 a7 b1’; ‘r1 c3 a4 b-2 r4 c2 a6 b2’; ‘r2 c1 a3 b1 r3 c4 a7 b-1’; ‘r2 c4
a6 b-2 r3 c1 a4 b2’; (b) ‘r1 c2 a3 b-1 r2 c4a6 b-2 r4 c3 a7 b1 r3 c1 a4 b2’; ‘r2 c1 a3 b1
r3 c4 a7 b-1 r1 c3 a4 b-2 r4 c2 a6 b2’. Theoptions when n = 5 are(a) ‘r1 c2 a3 b-1 r5
c4 a9 b1’; ‘r1 c4 a5 b-3 r5 c2 a7 b3’; ‘r2 c1 a3 b1 r4 c5 a9 b-1’; ‘r2 c5 a7 b-3 r4 c1 a5
b3’; ‘r3 c3 a6 b0’; (b) ‘r1 c2 a3 b-1 r2 c5 a7b-3 r5 c4 a9 b1 r4 c1 a5 b3’; ‘r2 c1 a3 b1 r1
c4 a5 b-3 r4 c5 a9 b-1 r5 c2 a7 b3’; ‘r3 c3 a6 b0’.
An n-queen solution is either asymmetric (changed by 180° rotation) or singly sym
metric (changed by 90° rotation but not 180°) or doubly symmetric (unchanged by 90°
rotation). Let Qa(n), Qs(n), Qd(n) be the number of such solutions that are essentially
different; then Q(n) = 8Qa(n) + 4Qs (n) + 2Qd (n) when n > 1. Furthermore there are
4Qs(n) + 2Qd(n) solutions to (a) and 2Qd(n) solutions to (b). Hence we can determine
the individual values just by counting solutions, and we obtain these results for small n:
n =4567 8 9 10 11 12 13 14 15 16 17
Qa(n) = 0 1 0 4 11 42 89 329 1765 9197 45647 284743 1846189 11975869
Qs(n) = 00 1 2 1 4 3 12 18 32 105 310 734 2006
Qd(n) = 11 0 0 0 0 0 0 4 4 0 0 32 64
We can reduce the solutions to (a) by a factor of 2, by simply eliminating the
options that contain {r1,ck} for k > fn/2]. We can reduce the solutions to (b) by a
July 26, 2019
7.2.2.1 answers to exercises 125
factor of 2 Ln/4J, by simply eliminating the options that contain {rj, ck} for j < fn/2] eight queens problem
and k > pn/2]. With these simplifications, the computation of Qd(16) needs only Gosset
Dudeney
70 K/; and then the computation of Qs(16) needs only 5 M/. Only 20 M/ are needed gadget
to determine that Qd (32) = 27 • 1589. RainBones puzzle
duplicate options
25. With 64 items, one for each cell of the chessboard, let there be 92 options, one for
each of the 92 solutions to the eight queens problem (see Fig. 68). Every option names
eight of the 64 items; so an 8-coloring is equivalent to solving this exact cover problem.
Algorithm X needs only 25 kilomems and a 7-node search tree to show that such a
,
mission is impossible. [In fact no seven solutions can be disjoint, because 1234567878563412
each solution touches at least three of the twenty cells 13, 14, 15, 16, 22, 27, 46718235
23854167
31, 38, 41, 48, 51, 58, 61, 68, 72, 77, 83, 84, 85, 86. See Thorold Gosset, 84236751
Messenger of Mathematics 44 (1914), 48. However, Henry E. Dudeney found 6517468721358243
the illustrated way to occupy all but two cells, in Tit-Bits 32 (11 September 512784
07348652
1897), 439; 33 (2 October 1897), 3.] 18650437
75421860
26. This is an exact cover problem with 92 + 312 + 396 + • • • + 312 = 3284 26835071
34072186
options (see exercise 7.2.2-6). Algorithm X needs about 32 megamems to find 52183704
80564213
the solution shown, and about 1.3 T/ to find all 11,092 of them. 61207345
27. Let Ujh and djh be secondary items for 1 < j < 2n and 1 < h < pn/2]. Insert the
gadget
uj1 uj2 ... ujfi/2^ u(j+1)[i/2^ ... uk[i/2^ ... uk2 uk1
into each option (16); also append similar options, but with ‘u’ changed to ‘d’, except
when i = n. [Solutions whose planar graph “splits” will be obtained more than once.
One such example is 12 10 8 6 4 11 9 7 5 4 6 10 12 5 7 9 11 3 1 2 1 3 2.]
28. (a) Denoting that formula by p(c0,t0;...; cl, tl), notice that if cj = tj + 1 — cj we
have p(c0,t0; ...; cl, tl) + p(c0, t0;...; cl, tl) = 1. Consequently the completion ratio is
1/2 if and only if cj = cj for all j, namely when tj = 2cj — 1.
(b) The ratio p(c0,t0;...; cl, tl) never has an odd denominator, because p/q + p'/q7
has an even denominator whenever q and p' are odd and q' is even. But we can get
arbitrarily close to 1/3, since p(2,4;... ; 2,4) = 1/3 + 1/(24 • 4l).
29. If T has only a root node, let there be one column, no rows. 011111000000000
101111000000000
Otherwise let T have d > 1 subtrees T1 , . . . , Td, and assume that 110111000000000
111010000000000
we’ve constructed matrices with rows Rj and columns Cj for each Tj . 111100000000000
Let C = C1 U • • • U Cd. The matrix for T is obtained by appending 000000011111000
000000101111000
three new columns {0, 1, 2} and the following new rows: (i) ‘0 1 2 and 000000110111000
000000111010000
all columns of C\Cj’, for 1 < j < d; (ii) ‘j and all columns of C’, for j G 000000111100000
000000111111111
{1, 2}. The matrix for the example tree has 15 columns and 14 rows. 111111000000111
111111111111010
30. Yes, assuming that duplicate options are permitted. Use the pre- 111111111111100
vious construction, but change ‘C\Cj’ to ‘C’ ifTj is a solution node. (Without duplicate
options, no two solution nodes can be siblings.)
31. (a) In step I4 of answer 8, insert p+j into the rth position of the list for ij , instead
of at the bottom, where r is uniform between 1 and len(ij ).
(b) In answer 9, when A < 0 also set r ^ 1; when A = 0, set r ^ r + 1, and change
i ^ p with probability 1/r.
32. (a) No. Otherwise there would be an option with no primary items.
(b) Yes, but only if there are two options with the same primary items.
(c) Yes, but only if there are two options whose union is also an option, when
restricted to primary items.
July 26, 2019
126 ANSWERS TO EXERCISES 7.2.2.1
(d) The number of places, j, where x = 1 and x' = 0 must be the same as the semidistance
number where x = 0 and x = 1. For if A has exactly k primary items in every option, Matsui
Matsui
exactly jk primary items are b eing covered in different ways. NP-complete
(e) Again distances must be even, because every solution also solves the restricted minimum remaining values heuristic
Schubert
problem, which is uniform. (Consequently it makes sense to speak of the semidistance integer programming
d(x,x')/2 between solutions of a quasi-uniform exact covering problem. The semidis Fischetti
tance in a polyform packing problem is the number of pieces that are packed differently.) Salvagnin
33. (Solution by T. Matsui.) Add one new column at the left of A, all 0s. Then add
two rows of length n + 1 at the bottom: 10 ... 0 and 11... 1. This (m + 2) x (n +1)
matrix A has one solution that chooses only the last row. All other solutions choose
the second-to-last row, together with rows that solve A.
34. (Solution by T. Matsui.) Assume that all 1s in column 1 appear in the first t rows,
where t > 3. Add two new columns at the left, and two new rows 1100 . . . 0, 1010 . . . 0
of length n + 2 at the bottom. For 1 < k < t, if row k was 1ak, replace it by 010ak if
k < t/2, 011ak if k > t/2. Insert 00 at the left of the remaining rows t + 1 through m.
This construction can be repeated (with suitable row and column permutations)
until no column sum exceeds 3. If the original column sums were (c1,...,cn), the
new A has 2T more rows and 2T more columns than A did, where T n=1(cj — 3).
One consequence is that the exact cover problem is NP-complete even when
restricted to cases where all row and column sums are at most 3.
Notice, however, that this construction is not useful in practice, because it disguises
the structure of A: It essentially destroys the minimum remaining values heuristic,
because all columns whose sum is 2 look equally good to the solver!
35. Take a matrix with column sums (c1 , . . . , cn), all < 3, and extend it with three
columns of 0s at the right. Then add the following four rows: (x1 , . . . , xn , 0, 1, 1),
(y1, . . . , yn , 1, 0, 1), (z1, . . . , zn, 1, 1, 0), and (0, . . . , 0, 1, 1, 1), where xj = [cj < 3], yj =
[cj < 2], zj = [cj < 1]. The bottom row must be chosen in any solution.
36. The following modifications (which work also with Algorithm C) will find all
solutions in lexicographic order; we can terminate early if we want only the first one.
Set LL ^ 0 in step X1. (We will use the MRV heuristic, but only on levels > LL.)
If rlink(0) = 0 and l = ll + 1 in step X2, visit the current solution as usual.
Otherwise, however, set LL ^ LL + 1 and do the following while l > LL (because the
current solution was not found lexicographically): Set l ^ l — 1, i ^ TOP(xl); uncover
the items = i in the option that contains xl (as in X6); uncover i (as in X7).
In step X3, if l = LL simply set i ^ RLINK(0). Otherwise use exercise 9, say.
If l < LL after setting l ^ l — 1 in step X8, set LL ^ l.
To get the lexicographically smallest solution to the n queens problem, make sure
that the first n items are r1 , r2 , . . . , rn . (The other primary items, cj , can follow in
any order.) The first solution for n = 32, found after 4.2 G^, has queens in columns
1, 3, 5, 2, 4, 9, 11, 13, 15, 6, 18, 24, 26, 30, 25, 31, 28, 32, 27, 29, 16, 19, 10, 8, 17, 12,
21, 7, 14, 23, 20, 22. (Without MRV the computation would have taken 35.6 G^.)
[The analogous problem for n = 48 is already quite difficult; that case was first
solved by Wolfram Schubert. The best results currently known for large n have been
obtained via sophisticated methods of integer programming: In Novemb er 2017, Matteo
Fischetti and Domenico Salvagnin were the first to solve the case n = 56 and many
larger cases, although n = 62 was still unsolved; see arXiv:1907.08246 [cs.DS] (2019),
14 pages. See also OEIS A141843 for the latest developments.]
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 127
Proof: The total number of set partitions into twenty subsets of size 5 is P = sample
100!/(20! • 5!2°) w 1098; the total number of possible options is N = (15°) = 75287520. frontier
n queens
The probability that any particular set partition occurs as a solution is the proba Rivin
bility that twenty given options occur in a random sample of m, with replacement, Zabih
Lamping
y
namely g(N,m,
g , , 20) = (2°)(—1)k(N - k)m/Nm = V, {m}t!(N-2°)/Nm.
k k t t t-2° .
If m
author
isn’t extremely large, this is almost the same as the probability without replace triply linked
,
ment, namelym-2°
(N m2°)/(N) ~ (m/N)2°. The expected number of solutions when binary search tree
backtracking algorithm
m = (500,1000,1500), respectively, is Pg(N,m, 20) w (.000002, 2.41, 8500). asymptotically
theory vs practice
40. Set fm ^ 0 and fk-1 ^ fk | rk for m > k > 1. The bits of uk represent items practice vs theory
that are being changed for the last time. n queen bees
Let uk = u' + u", where u' = uk & p. If uk =0 at the beginning of step N4, regular expression
0-origin indexing
we compress the database as follows: For N > j > 1, if sj & u' = u', delete (sj ,Cj); multiplication tables
otherwise if sj & u" = 0, delete (sj, Cj) and insert ((sj & uk) | u', Cj). binary operators
isotopic
To delete (sj, Cj), set (sj, Cj) ^ (sN, cN) and N ^ N — 1. magic squares
When this improved algorithm terminates in step N2, we always have N < 1. sudoku solution
Furthermore, if we let pk = r1 | ••• | rk-1, the size of N never exceeds 2vk, where Boyer
44. No. The 33rd digit is 0. [A sudoku whose clues are n’s first 32 digits was de Ruiter
first constructed by Johan de Ruiter in 2007; see www.puzzlepicnic.com/puzzle?346. Thoen
van de Wetering
Furthermore, n’s first 22 digits can actually be arranged in a circle to give a uniquely author
solvable sudoku, if we also require the elements of both main diagonals to be distinct! sudoku setup program
hidden
See Aad Thoen and Aad van de Wetering, Exotische Sudoku’s (2016), 144.] naked
45. Step X3 chooses p44, p84, p74, p24, p54, p14, p82, p42, p31 , p32, p40, p45, p46, p50, pointing pair
Gould
p72 , p60 , p00 , p62 , p61 , p65 , p35 , p67 , p70, p71 , p75 , p83 , p13, p03 , p18 , p16 , p07 , p01 , p05 , Mepham
p15 , p21 , p25 , p76 , p36 , p33, p37 , p27, p28 , p53, p56 , p06 , p08 , p58, p77 , p88 , in that order. Berthier
46. The lists for items p44, p84, r33 , r44, r48 , r52 , r59 , r86 , r88 , c22 , c43 , b07, b32 , b39 ,
b43, b54, and b58 have length 1 when Algorithm X begins to tackle puzzle (29 a). Step
X3 will branch on whichever item was placed first in step X1. (The author’s sudoku
setup program puts p before r before c before b in that step.)
47. r13, c03, b03, b24, b49, b69. The latter three were hidden already in (32).
48. In case (a) we list the available columns; in case (b) we list the available rows:
123456789 012345678
0 45
3 6 8 0
12
45
7
12
45 45
7
2 1
7
5 1 1 345
7
345
7
345
0
3
6
0
2 345 68
3
678 6
345
1 0 78
2
1 3 5 4
78
2
4
68
2
4
67
2
78
2 7
2
5 35
7
2 12
0 8 4 6 35 35
35
7
12 1
2 6
012
7 3
012
8
012
45
7
012
45
02
45
7
1
7
5 3 4 1 8 2 7 5 0 3
6
3
6
3 12
345
78
12
78 78 6
12
45
7
2 12
345
12
345
68
45
67
2
0 4 67
2
5
7
2
345
7
2
1345 3
67
35
8 0
3
6
(a) (b)
4 3
12
78 5 0
12
7
2
6 3
12
8 7
2
4 5 0 6 34 8 5 1 7 34 2
5 3
12
78
012
78 5
012
6 6
012
3
012
3
68
02
67 78
6 678
2 02
5 35 35 35
7 7
012 02
012
3 4
012
3
6 68
678 6
1
6 45
78 6 78
0
45 1
0
45
78
0
45
3 2 7 68
2 02
5 345
012 02
012
345 3
68
1
35
345
7
3
6
1
345
7 12
5
012
4
012
5
6
012
5
7 8 3 8
2
5
8 6
012 02
012
345 3
1 012
35 345
3
7
8 5
8 4 2 7 3
0
5
8
0
5
1 6 9 3
02
6 7 4
02
8
012
5
1
5
(Notice that “hidden” singles and pairs, etc., become “naked” in this representation.
Similar plots, which relate boxes to values, are also possible; but they’re trickier,
because boxes aren’t orthogonal to rows or columns.)
49. (a) For columns, remove all items rik and bxk , as well as cjk with j = j0; let
uj --- vk when an option contains ‘pij0 cj0k’. For boxes, remove all rik , cjk , and bxk with
x = xo; let Uj — Vk when an option contains ‘P(3Lx0/3j + Lj/3J)(3(x mod 3)+(j mod 3)) bxok’.
(b) The n - q non-neighbors of a hidden q-tuple (e.g., {u3, u8, u1}) are “naked.”
(c) By (b) it suffices to list the naked ones (and only those for which q < r). Let’s
denote the option in (30) by ijk. In row 4 we find the naked pair {u3, u8}, hence we can
delete options 411, 417, 421, 427, 471; also the naked triple {u1 , u3, u8}, so we can also
delete option 424. There’s no nakedness in the columns. The naked triple {u0, u3, u6}
in box 4 allows deletion of options 341, 346, 347, 351, 356, 357.
(d) Let ui --- vj if there’s an option that contains ‘rik0 cjk0’. When k0 = 9 there’s
a naked pair {u1 , u5 }, so we can delete options 079 and 279.
[Many other reductions have been proposed. For example, (33) has a “pointing
pair” in box 4: Since ‘4’ and ‘8’ must occupy that box in row 3, we can remove options
314, 324, 328, 364, 368, 378. Classic references are the early tutorials by W. Gould, The
Times Su Doku Book 1 (2005); M. Mepham, Solving Sudoku (2005). A comprehensive
theory, applicable also to many other problems, has been developed by D. Berthier,
Pattern-Based Constraint Satisfaction and Logic Puzzles (2012).]
July 26, 2019
130 ANSWERS TO EXERCISES 7.2.2.1
50. Such a puzzle must add a 7 or 8 in one of 18 places, because (29c) 9 3 4 5 1 7 6 author
has just 2 solutions. So there are 36 of them (18 isomorphic pairs). 7 6 2 4 9 3 1 7 5 canonical form
7 5 1 7 4 9 3 Eleven (anonymous?)
2 7 5 9 7 1 6 3 4 automorphisms
51. We can solve this problem with Algorithm M, using options (30) 6 4 9 3 5 1
Russell
with k = 8 and giving multiplicity 2 to each of the items ri7, cj7 , bx7. 1 7 3 5 9
4 1 7 6 5 9 3
There are six solutions, all of which extend the partial solution shown. 3 2 7 1 9 5 6
Only one yields a sudoku square when we change half of the 7s to 8s. 5 9 6 3 7 4 1
(b) Only 44 = 256 sets of four clues meet the conditions of part (a), for each of A and B;
we can test them all. Reducing by the automorphisms leaves two for A and eleven for B :
(There also are 22 essentially different shidoku puzzles with five irredundant clues, and
a unique puzzle with six. The latter, which is solved by A, is shown above at the
bottom left; it cannot omit a clue without having an empty region in either C or CT .
These results were discovered by Ed Russell in 2006.)
54. For example, removing clues one at a time shows that only 10 of the 32 givens are
actually essential. The best strategy for finding all minimal X is probably to examine
candidate sets in order of decreasing cardinality: Suppose W С X, and suppose that
previous tests have shown that the solution is unique, given X , but not given X \ w for
any w G W. Thus X is minimal if W = X. Otherwise let X \W = {x1,... , xt}, and test
X \ xi for each i. Suppose the solution turns out to be unique if and only if i > p. Then
we schedule the t — p candidate pairs (WU{x1,... , xp}, X\xi), p < i < t, for processing
in the next round. With suitable caching of previous results, we can avoid testing the
same subset of clues more than once. Furthermore we can readily modify Algorithm X
so that it backtracks immediately after discovering a single unwanted solution.
All 777 minimal subsets were found in this manner, involving 15441 invocations
of Algorithm X, but needing a total of only about 1.5 gigamems of computation.
Altogether (1, 22, 200, 978, 2780, 4609, 4249, 1950, 373, 22) candidate pairs were
examined in rounds (32, 31, . . . , 23); and exactly (8, 154, 387, 206, 22) solutions were
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 131
found of sizes (27, 26, 25, 24, 23). The lexicographically last 23-clue subset, which is monotone Boolean function
illustrated below, turns out to be a fairly tough puzzle, with 220 nodes in its search tree. order ideals
prime implicants
(Let f (x1, . . . , x32) be the monotone Boolean function ‘[the solution is unique, author
given the clues with xj = 1]’. This problem essentially asks for f’s prime implicants.) SAT solver
isotopism
1 1 2 3 1 6 8 Dobrichev
4 1 9 7 8 9 5 1 automorphisms
6 5 9 4 Thoen
van de Wetering
5 8 9 2 3 4 3 5 7
(29a) 7 3 2 (28a) ; (28b) 9
3 8 4 5 6 7 8 1
2 6 4 5 6 7 7
3 8 6 4 8 2
3 7 5 9 1 8 3 5
55. If only one of those nine appearances has been specified, the other eight can always
be permuted into another solution. And the entire diagram can be partitioned into nine
disjoint sets of nine, all with the same property, thus requiring at least 2 • 9 clues.
This argument proves that all 18-clue characterizations must have a very special
form. The interesting solution above makes a particularly satisfying puzzle. (The
author found it with the help of a SAT solver; see Section 7.2.2.2.)
The same argument shows that (28b) needs at least 18 clues. But this time the
corresponding SAT instance is unsatisfiable. Moreover, any 19-clue solution must have
three clues in just one critical group of nine; the associated SAT instance, which insists
on having at least one clue in each of the 2043 subsets of at most 18 cells that can be
rearranged into new solutions, also is unsatisfiable. (Proved in 177 M^.) But hurrah,
the special structure does lead to 20-clue examples, like the one above.
(The constructions for (28b) apply also to (28c), via the isotopism in answer 43.)
56. (We assume that a decent sudoku problem has only one solution.)
1 2 3 4 5 6 7
An example with 40 irredundant clues, shown here, was first discovered 3 4 5 6 1 8 2
1 5 8 2 6
by Mladen Dobrichev in 2014, after examining a huge number of cases. 8 6 1
2 7 5
(Incidentally, the solution to this problem has no automorphisms.) An 8
3 7
6
5
7
2 8
57. There are only 2 • 3! • 3! • 3! • 3! = 2592 possibilities for each box. So we can set up an
exact cover problem with 9 • 2592 options, each of which names a box, nine row-column
pairs, three horizontal trios, and three vertical trios. We can assume by symmetry that
there’s only one option for box 0, namely ‘b0 r01 c01 r04 c14 r07 c27 r18 c08 r12 c12 r15
c25 r26 c06 r29 c19 r23 c23 h147 h258 h369 v168 v249 v357 ’. Furthermore row 0 can be
restricted to 1472ab3cd, where {A, C} = {5, 6} and {B, D} = {8, 9}. That reduces the
number of options to 16417; and Algorithm X quickly ((58+54)M^) finds 864 solutions.
Such solutions were first discovered by A. Thoen and A. van de Wetering; see
Thoen’s book Sudoku Patterns (2019), §2.7. All 864 are isomorphic under sudoku
solution-preserving permutations of rows and columns. One of the nicest is
1 4 7 2 5 9 3 6 8
8 2 5 7 3 6 9 1 4 which has a
A B C
6 9 3 4 8 1 5 7 2 remarkable D E F
2 6 9 3 4 8 1 5 7 inner symmetry G H I
7 3 4 9 1 5 8 2 6
5 8 1 6 7 2 4 9 3 between I B. D
diagonally HAF
3 5 8 1 6 7 2 4 9
G C E
9 1 6 8 2 4 7 3 5 adjacent boxes:
4 7 2 5 9 3 6 8 1
July 26, 2019
132 ANSWERS TO EXERCISES 7.2.2.1
58. Use the standard 729 sudoku options (30); but also include queen items ‘a(i+j)k secondary
b(i-j-)k’ in option (i, j, k) when k < 7. Furthermore, in order to avoid getting each S Grabarchuk
P Grabarchuk
solution 7! 2! = 10080 times, force row 0 by adding a new primary item “*’ and new Gardner
secondary items ‘*j’ for 0 < j < 9, together with 20 options “* *0:f(0,p,q) ... straight n-ominoes
rotation
*8:f (8,p,q)’ for 0 < p < q < 9, p + q < 9, where f(j,p,q) = (j = p? 8: j = q? 9: reflection
1 + j — [j >p] — [j >q]). There are only two solutions, found in 3 G^, both centrally symmetries
symmetric. (See Appendix E, and Thoen’s book Sudoku Patterns (2019), §3.4.) 180° rotation
central symmetry
59. When ps precede rs precede cs precede bs in X1, the tree sizes are 1105, 910, 122. reflection
reflection symmetry
3 1 2 5 8 6 7 4 9 G T A R D N E I M W V Y N A L T K F
9 4 1 8 3 7 2 5 6 D N T G I R A M E F T L W K Y A N V
2 6 5 9 4 8 3 1 7 I G E T N A M D R K A V T N F L W Y
7 3 4 2 6 9 1 8 5 T I R N A M D E G N K F L T V W Y A
(34a) 1
6
8
9
9
7
7
4
5
2
3
5
6
8
2
3
4 ;
1
(34b) R
M
A
R
I
N
D
I
M
E
E
D
N
G
G
T
T
A
Y
A
F
L
T
W
A
K
L
V
W
N
N
Y
V
F
K
T
5 2 3 6 1 4 9 7 8 A M D E R G T N I V W N Y F A K T L
8 5 6 1 7 2 4 9 3 N E M A G T I R D L Y K F W T V A N
4 7 8 3 9 1 5 6 2 E D G M T I R A N T N A V Y K F L W
60. Using the options (30), items rik and cjk should be secondary when row i or
column j contains fewer than 6 cells. The puzzles are fun to solve by hand; but in a
pinch, Algorithm X will traverse search trees of sizes 23, 26, and 16 to find the answers:
5
(a) 6
1
4
2
5.6 2
6 1 3 2
4 3 (b)
3
6
4
2
5
1
1 5
4
5 6
6
1
2
3 (c)
3 64
4 5 3 6
2 1
1 5 3 2 6. 4 1 4 3 25 6 1 2
2 6 4|3 5 1 5 3 4 2 3 4 2
4 3 1 5 2 6 dt 3 6 5
[These are the first of 26 elegant puzzles announced by Serhiy and Peter Grabarchuk
on Martin Gardner’s 100th birthday (21 October 2014) and posted at puzzlium.com.]
61. Exactly 1315 of the 12*55 = 53130 ways to retain five clues result in a unique solu
tion, and 175 of them involve all five digits. The lexicographically first is Fig. A-2(a).
62. Follow the hint; the undesired straight n-ominoes can be rejected easily in step R2
by examining vn-1 and v0. This quickly produces (16, 105, 561, 2804, 13602) box
options, for n = (3, 4, 5, 6, 7), which can be fed to Algorithm X to get jigsaw patterns.
There are no patterns for n = 3. But n = 4 has 33 patterns, which divide into
eight equivalence classes under rotation and/or reflection:
1 1 222448
(The number of symmetries is shown below each arrangement; notice that 8/1 + 8/1 +
8/2 + 8/2 + 8/2 + 8/4 + 8/4 + 8/8 = 33.) Similarly, n = 5 has 266 equivalence classes,
representing 256 • (8/1) + 7 • (8/2) + 3 • (8/4) = 2082 total patterns; n = 6 has 40237
classes, representing 39791 • (8/1) + 439 • (8/2) + 7 • (8/4) = 320098 patterns in all.
The computation gets more serious in the case n = 7, when Algorithm X needs
about 1.9 T^ to generate the 132,418,528 jigsaw patterns. These patterns include
16,550,986 classes with no symmetry, and 2660 with one nontrivial symmetry. The
latter break down into 2265 that are symmetric under 180° rotation, 354 that are
symmetric under horizontal reflection, and 41 that are symmetric under diagonal
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 133
(It’s not difficult to generate all of the symmetric solutions for slightly higher values
of n; three of the classes for n = 8, shown above, have more than 2 symmetries. And
the case n = 9 contains two patterns with 8-fold symmetry besides the standard sudoku
boxes: See Fig. A-2(b) and (c), where the latter might be called windmill sudoku! For
complete counts for n = 8 and n = 9, with straight n-ominoes allowed, see Bob Harris’s
preprint “Counting nonomino tilings,” presented at G4G9 in 2010.)
1 58 6 4 3 9 7 2
2 6 9 5 7 8 1 3 4
3 7 4 1 9 2 5 6 8
4 9 2 8 6 7 3 1 5
(d) 5 3 7 4 2 1 6 8 9
6 8 1 3 5 9 2 4 7
7 2 6 9 1 4 8 5 3
8 4 5 2 3 6 7 9 1
9 1 3 7 8 5 4 2 6
66. (Puzzles like this might be too difficult for humans, but not for Algorithm C.) XCC problem
Extend the 729 options (30) by adding ‘ij:k’, where ij is a new secondary item for color controls
automorphisms
0 < i, j < 9- Also add eighteen new primary items k for 1 < k < 9 and sj for 0 < j < 9, Brouwer
where k represents card k and sj represents a slot in the 3x3 array. Each item k has nine backtrack program
Bousquet-Melou
options, for the nine slots in which it might be placed; for example, the options for item 2 Fedou
are ‘2 S0 00:2 11:3 22:4 20:1’, ‘2 S1 03:2 14:3 25:4 23:1’, . . . , ‘2 S8 66:2 77:3 88:4 86:1’. generating function
There are 9! ways to place the cards in slots; but only 9!/(3! 3!) = 10080 are actu Klarner
Rivest
ally different, because the rows and columns can be permuted independently without
changing the number of sudoku solutions. Suppose card cj goes into slot Sj ; then we
can assume without loss of generality that c0 = 1 and that c4 = min(c4 , c5 , c7 , c8). (To
incorporate these constraints, give only one option for card 1 and only eight options
for cards 2-9; use ordering tricks like (26) to ensure that c4 < c5, c4 < c7, c4 < c8.)
With this understanding, puzzle (i) has only one solution, and only when c0 . . . c8 =
192435768. (That solution has six automorphisms, in the sense of exercise 114.) Puzzle
(ii) has a unique solution when c0 . . . c8 = 149523786. It also has ten sudoku solutions
when the slot permutation is 149325687; so we can’t use that placement.
67. (a) (Solution by A. E. Brouwer, homepages.cwi.nl/~aeb/games/sudoku/nrc.html,
2006.) The four new boxes force also aaaaaaaaa, . . . , eeeeeeeee to be rainbows.
e a a a e b b b e 3 2 7 1 5 4 8 6 9 3 1 6 8 9 4 7 2 5
c c c 6 1 5 8 2 9 4 7 3 5 7 8 3 2 6 4 1 9
c c c 8 9 4 3 7 6 2 1 5 4 2 9 5 1 7 3 8 6
c c c 9 6 2 7 1 5 3 8 4 7 4 1 6 3 9 2 5 8
e a a a e b b b e (i) 7 4 3 9 8 2 1 5 6 (ii) 2 9 5 7 8 1 6 3 4
d d d 5 8 1 4 6 3 7 9 2 8 6 3 4 5 2 9 7 1
d d d 1 3 6 2 9 8 5 4 7 9 8 7 1 4 3 5 6 2
d d d 4 7 9 5 3 1 6 2 8 6 5 2 9 7 8 1 4 3
e a a a e b b b e 2 5 8 6 4 7 9 3 1 1 3 4 2 6 5 8 9 7
(b) Introduce new primary items b'yk for 0 < y < 9 and 1 < k < 9. Add b'yk to
option (30) with y = 3|_Тт/3_| + L?t/3J, where т is the permutation (03)(12)(58)(67).
(c) With items b'yk only considered for y G {0, 2, 6, 8}, Algorithm X’s search tree
grows from 77 nodes to 231 for (i), and from 151 nodes to 708 for (ii).
[Puzzle (ii) is a variant of an 11-clue example constructed by Brouwer. The
minimum number of clues necessary for hypersudoku is unknown.]
(d) True. (That’s the permutation т in (b), applied to both rows and columns.)
68. (a) A simple backtrack program generates all convex n-ominoes whose top cell(s)
are in row 0 and whose leftmost cell(s) are in column 0. [This problem has respectively
(1, 2, 6, 19, 59, 176, 502) solutions for 1 < n < 7; see M. Bousquet-Melou and J.-M.
Fedou, Discrete Math. 137 (1995), 53-75, for the generating function.] The resulting
(1, 4, 22, 113, 523, 2196, 8438) placements into an n x n box yield exact cover problems
as in answer 62. Considering symmetries, we find 1 • (8/4) = 2 patterns when n = 2;
1-(8/1)+1-(8/4) = 10 patterns when n = 3; 10^(8/1)+7^(8/2)+4^(8/4)+b(8/8) = 117
whenn = 4; 355^(8/1) + 15^(8/2)+4^(8/4) = 2908 whenn = 5; 20154^(8/1)+342^(8/2) +
8 • (8/4) = 162616 when n = 6; 2272821 • (8/1) + 1181 • (8/2) + 5 • (8/4) = 18187302 when
n = 7. (Exercise 62 had different results because it disallowed straight n-ominoes.)
(b) There are 325 such nonominoes touching row 0 and column 0, leading to 12097
placements and 1014148 • (8/1) + 119 • (8/2) + 24 • (8/4) + 1 • (8/8) = 8113709 patterns.
If we exclude the 3 x 3 nonomino, and its 49 placements, the number of patterns goes
down to 675797 • (8/1) = 5406376.
[Convex polyominoes were introduced by Klarner and Rivest; see answer 303.]
July 26, 2019
7.2.2.1 answers to exercises 135
69. Say that an “Nk” is a suitable nonomino placement that has k Bs B B L B L L LL B multiplicities
L L L B L L LB L
and 9 - k Ls. Only two cases give seven wins for B: 1 N6 , 6 N5 , 2 N0 ; B B L B L B BL B
author
Garfinkel
7 N5 , 1 N1 , 1 N0 . With the given voting pattern there are respectively LL L L
B B B L
L
L
L l|l L
Adler
B L L B
(1467, 2362, 163, 2) options for N6, N5, N1, N0. Algorithm M provides L B L B B B B B B Patent
B B L B B B ft L Jahn
the desired multiplicities. After 12 ,\l// of computation we find that there L B L L L L quadrille
are no solutions in case 1 but 60 solutions in case 2, one of which is shown.L LIBIL B Bl
L L
Lucas
(Of course the author does not recommend secret deals such as this! The point Delannoy
Philpott
is that unfair gerrymandering is easy to do and hard to detect. Indeed, a trial of 1000 dimer tilings
random voter patterns, each with 5/4 split in the nine standard 3 x 3 districts, included heavy-tailed distribution
696 cases that could be gerrymandered to seven Big-Endian districts using only convex empirical standard deviation
Keller
nonominoes that fit in a 5 x 5. Eight of those cases could also achieve a 4 x 4 fit.)
[Similar studies, using realistic data, go back to R. S. Garfinkel’s Ph.D. thesis
Optimal Political Districting (Baltimore: Johns Hopkins University, 1968).]
70. In (a), four pieces change; in (b) the solution is unique:
Notice that the spot patterns ,, and H are rotated when a domino is placed ver
tically; these visual clues, which would disambiguate (a), don’t show up in the matrix.
(Dominosa was invented by O. S. Adler [Reichs Patent #71539 (1893); see his
booklet Sperr-Domino und Dominosa (1912), 23-64, written with F. Jahn]. Similar
“quadrille” problems had been studied earlier by E. Lucas and H. Delannoy; see Lucas’s
Recreations Mathematiques 2 (1883), 52-63]; W. E. Philpott, JRM 4 (1971), 229-243.)
71. Define 28 vertices Dxy for 0 < x < y < 6; 28 vertices ij for 0 < i < 7, 0 < j < 8,
and i + j even; and 28 similar vertices ij with i + j odd. The matching problem has
49 triples of the form {Dxy, ij, i(j+1)} for 0 < i, j < 7, as well as 48 of the form
{Dxy, ij, (i+1)j} for 0 < i < 6 and 0 < j < 8, corresponding to potential horizontal
or vertical placements. For example, the triples for exercise 70(a) are {D06, 00, 01},
{D56, 01, 02}, . . . , {D23, 66, 67}; {D01, 00, 10}, {D46, 01, 11}, . . . , {D12, 57, 67}.
72. Model (i) has M = 56!/8!7 « 4.10 x 1042 equally likely possibilities; model (ii)
has N = 1292697 • 28! • 221 ~ 8.27 x 1041, because there are 1292697 ways to pack 28
dominoes in a 7 x 8 frame. (Algorithm X will quickly list them all.) The expected
number of solutions per trial in model (i) is therefore N/M ~ 0.201.
Ten thousand random trials with model (i) gave 216 cases with at least one
solution, including 26 where the solution was unique. The total number x of solutions
was 2256; and x2 = 95918 indicated a heavy-tailed distribution whose empirical
standard deviation is ~ 3.1. The total running time was about 250 M^.
Ten thousand random trials with model (ii), using random choices from a precom
puted list of 1292687 packings, gave 106 cases with a unique solution; one case had 2652
of them! Here x = 508506 and x2 = 144119964 indicated an empirical mean of
~ 51 solutions per trial, with standard deviation ~ 109. Total time was about 650 M^.
73. From 66110144/26611514/52132140/55322200/53242006/36430565/33643054 we
get 730,924 solutions, which is the current record. This array, found by Michael Keller
July 26, 2019
136 ANSWERS TO EXERCISES 7.2.2.1
in 2004, has the surprising property that every candidate placement, except for the MCC problem
‘21’ in ‘521’, occurs in at least one solution. (In fact, in at least 31,370 solutions!) author
tatami tiling
74. One way to obtain candidate arrays is to formulate an MCC problem: Given one nonsharp
randomization
of the 1292697 matchings of answer 72, let there be options ‘Puv xy tu:x tv:y’, ‘Puv isomorphic
xy tu:y tv:x’ for uv in the matching, and ‘Quv Dxy tu:x tv:y’, ‘Quv Dxy tu:y tv:x’ for isomorphic
Bennett
uv not in the matching; here 0 < x < y < 6, and duplicate options are omitted when Schroder
x = y. Give each Dxy multiplicity 3. Also add 28 further options ‘# Dxy ’, where # Caltech
has multiplicity 15 (because 15 pairs xy should have only two spurious appearances). author
groups
For fun, the author chose a tatami tiling for the matching (see exercise 7.1.4 quasigroup
215), and obtained one candidate every 70 ,\l// or so when the nonsharp variant of semisymmetric quasigroup
Mendelsohn triples
Algorithm M was applied with randomization as in exercise 31. Surprisingly, the first
Schroder
10000 candidates yielded 2731 solutions, of which the hardest (with a 572-node search totally symmetric quasigroups
tree) was 15133034/21446115/22056105/65460423/22465553/61102332/63600044. Stein
Steiner triple systems
[See www.puzzlelaboratory.com/DominoGG.html.]
75. (a) (x ◦ y) ◦ x = (x ◦ y) ◦ (y ◦ (x ◦ y)) = y.
(b) All five are legitimate. (The last two are gropes because f (t + f (t)) = t for
0 < t < 4 in each case; they are isomorphic if we interchange any two elements. The
third is isomorphic to the second if we interchange 1 о 2. There are 18 grope tables of
order 4, of which (4, 12, 2) are isomorphic to the first, third, and last tables shown here.)
(c) For example, let x ◦ y = (-x - y) mod n. (More generally, if G is any group
and if a G G satisfies a2 = 1, we can let x ◦ y = ax-ay-a. If G is commutative and
a G G is arbitrary, we can let x ◦ y = x-y-a.)
(d) For each option of type (i) in an exact covering, define x ◦ x = x; for each of
type (ii), define x ◦ x = y, x ◦ y = y ◦ x = x; for each of type (iii), define x ◦ y = z,
y ◦ z = x, z ◦ x = y. Conversely, every grope table yields an exact covering in this way.
(e) Such a grope covers n2 items with k options of size 1, all other options of size 3.
[F. E. Bennett proved, in Discrete Mathematics 24 (1978), 139-146, that such gropes
exist for all k with 0 < k < n and k = n2 (modulo 3), except when k = n = 6.]
Notes: The identity xo(yox) = y seems to have first been considered by E. Schroder
in Math. Annalen 10 (1876), 289-317 [see ‘(C0)’ on page 306], but he didn’t do much
with it. In a class for sophomore mathematics majors at Caltech in 1968, the author de
fined gropes and asked the students to discover and prove as many theorems about them
as they could, by analogy with the theory of groups. The idea was to “grope for results.”
The official modern term for a grope is a real jawbreaker: semisymmetric quasigroup.
76. (a) Eliminate the n items for xx; use only the 2 n3 options of type (iii) for which
y = z. (Idempotent gropes are equivalent to “Mendelsohn triples,” which are families
of n(n - 1)/3 three-cycles (xyz) that include every ordered pair of distinct elements.
N. S. Mendelsohn proved [Computers in Number Theory (New York: Academic Press,
1971), 323-338] that such systems exist for all n = 2 (modulo 3), except when n = 6.
(b) Use only the n+2 1 items xy for 0 < x < y < n; replace options of type (ii)
by ‘xx xy’ and ‘xy yy’ for 0 < x < y < n; replace those of type (iii) by ‘xy xz yz’
for 0 < x < y < z < n. (Such systems, Schrooder’s ‘(C1) and (C2)’, are called totally
symmetric quasigroups; see S. K. Stein, Trans. Amer. Math. Soc. 85 (1957), 228
256, §8. If idempotent, they’re equivalent to Steiner triple systems.)
(c) Omit items for which x = 0 or y = 0. Use only the 2 n-3 1 options of type (iii)
for 1 < x < y, z < n and y = z. (Indeed, such systems are equivalent to idempotent
gropes on the elements {1, . . . , n - 1}.)
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 137
77. Use primary items v and v' for each vertex of G and H; also secondary items ee' word search
for each pair of vertices e and e in G and the complement of H. There are n2 options, CUTOFF
namely ‘v vz |Je(v) e,(v,) e(v)e/(v/)’, where e(v) ranges over all edges v — u in G and
e/(v/) ranges over all nonedges v' —— u' in H. (The solutions to this problem are the
one-to-one matchings v <—> v' of the vertices such that u — v implies u' — v'.)
78. For example, catalandauborel, gramarkoffknopp , abelweierstrass, bertrand-
hermite, cantorfrobenius , glaisherhurwitz , hadamardhilbert , henselkirchhoff ,
jensensylvester , mellinstieltjes , nettorungestern, minkowskiperron.
79. In an n x n array for word search, every k-letter word generates (n + 1 — k) • n • 4
horizontal/vertical options and (n + 1 — k)2 • 4 diagonal options. So the desired answer
is (2, 5, 6, 5, 3, 5, 0, 1) • (1296, 1144, 1000, 864, 736, 616, 504, 400) = 24320.
80. Item q is selected at level 0, trying option x0 = 8, ‘q x y : A p’. We cover q , then
cover x, then purify y to color A, and cover p; but at level 1 we find that item r’s list is
empty. So we backtrack: Uncover p, unpurify y, uncover x — and try option x0 = 20,
‘q x:A’, hence purifying x to color A. This time at level 1 we try x1 = 12, ‘p r x:A
y’. That causes us to cover p, then cover r, and then (since x is already purified) to
cover y. At level 2 we discover that we’ve found a solution! Here’s what’s in memory:
i: 0 1 2 3 4 5 6
NAME(i): — p q r x y —
LLINK(i): 0 0 1 0 6 4 4
RLINK(i): 0 3 3 0 6 6 4
x: 0 1 2 3 4 5 6
LEN(x): — 1 2 1 2 0 0
ULINK(x): — 12 20 23 18 5 —
DLINK(x): — 12 8 23 14 5 10
x: 7 8 9 10 11 12 13
TOP(x): 1 2 4 5 -1 1 3
ULINK(x): 1 2 4 5 7 1 3
DLINK(x): 12 20 14 15 15 1 23
COLOR(x): 0 0 0 A — 0 0
x: 14 15 16 17 18 19 20
TOP(x): 4 5 -2 1 4 -3 2
ULINK(x): 4 5 12 12 14 17 8
DLINK(x): 18 24 18 1 4 21 2
COLOR(x): -1 0 — 0 B — 0
x: 21 22 23 24 25
TOP(x): 4 -4 3 5 -5
ULINK(x): 18 20 3 5 23
DLINK(x): 4 24 3 5 —
COLOR(x): A — 0 B —
81. Almost true, if top and color are stored in the same octabyte (so that only one
is charged to read both). The only difference is when processing the input, because
Algorithm X has no color fields to initialize but Algorithm C zeroes them out.
82. True; the len field of secondary items doesn’t affect the computation.
83. Before setting i ^ TOP(x0) in step C6 when l = 0, let node x be the spacer at
the right of x0’s option, and set j ^ TOP(x — 1). If j > N (that is, if that option ends
with the secondary item j), and if color(x — 1) = 0, cover(j).
84. Let CUTOFF (initially to) point to the spacer at the end of the best solution found
so far. We’ll essentially remove all nodes > cutoff from further consideration.
July 26, 2019
138 ANSWERS TO EXERCISES 7.2.2.1
Whenever a solution is found, let node pp be the spacer at the end of the option sorted
for which xk = max(x0,..., xl-1). If PP = CUTOFF, set CUTOFF ^ PP, and for 0 < k < l profile
search tree
remove all nodes > cutoff from the list for top(xk). (It’s easy to do this because the backtrack tree
list is sorted.) Minimax solutions follow the last change to cutoff. updates
cleansings
Begin the subroutine ‘uncover'(i)’ by removing all nodes > CUTOFF from item i’s
list. After setting d ^ DLINK(q) in unhide'(p), set DLINK(q) ^ d ^ x if d > CUTOFF.
Make the same modifications also to the subroutine ‘unpurify(p)’.
Subtle point: Suppose we’re uncovering item i and encounter an option ‘i j . . . ’
that should be restored to the list of item j; and suppose that the original successor
‘j a . . . ’ of that option for item j lies below the cutoff. We know that ‘j a . . . ’ contains
at least one primary item, and that every primary item was covered before we changed
the cutoff. Hence ‘j a . . . ’ was not restored, and we needn’t worry about removing it.
We merely need to correct the dlink, as stated above.
85. Now let cutoff be the spacer just before the best solution known. When resetting
cutoff, backtrack to level k - 1, where xk maximizes {x0, . . . , xl-1}.
86. The steps below also estimate the profile of the search tree. Running time is
estimated in terms of “updates” and “cleansings.” The user specifies a random seed
and a desired number of trials; the final estimates are the averages of the (unbiased)
estimates from each trial. Here we specify only how to make a single trial.
In step C1, also set D ^ 1.
In step C2, estimate that the search tree has D nodes at level l. If rlink(0) = 0,
also estimate that there are D solutions.
In step C3, let 0 be the number of options in the list of the chosen item i. If 0 = 0,
estimate that there are 0 solutions, and go to C7.
At the end of step C4, let k be uniformly random in [0. .0 — 1]; then set xl ^
dlink(xl), k times.
Just before setting l ^ l + 1 at the end of step C5, suppose you’ve just done
U updates and C cleansings. (An “update” occurs when ‘cover’ sets llink(r) or
‘hide’ sets ulink(d). A “cleansing” occurs when ‘commit’ calls ‘purify’ or ‘purify’ sets
COLOR(q) <-- 1.) Estimate that level l does D(U' + 0 • U) updates and DC cleansings,
where U' is the number of updates just done in step C4. Then set D ^ 0 • D.
Step C6 now should do absolutely nothing. Steps C7 and C8 don’t change.
Upon termination, all data structures will have been returned to their original
state, ready for another random trial. These steps will have estimated the number
of nodes, updates, and cleansings at each level. Sum these estimates to get the total
estimated number of nodes, updates, and cleansings.
87. Use 2n primary items ai , dj for the “across” and “down” words, together with n2
secondary items ij for the individual cells. Also use W secondary items w, one for each
legal word. The XCC problem has 2Wn options, namely ‘ai i1:c1 . . . in:cn c1 . . . cn’ and
‘dj 1j:c1 ... nj:cn c1 ... cn’ for 1 < i, j < n and each legal word c1.. . cn. (See (no).)
We can avoid having both a solution and its transpose by introducing W further
secondary items w' and appending c1. .. cn' at the right of each option for a1 and d1.
Then exercise 83’s variant of Algorithm C will never choose a word for d1 that it has
already tried for a1. (Think about it.)
But this construction is not a win for “dancing links,” because it causes massive
amounts of data to go in and out of the active structure. For example, with the five-
letter words of words(5757), it correctly finds all 323,264 of the double word squares,
but its running time is 15 tera mems! Much faster is to use the algorithm of exercise
July 26, 2019
7.2.2.1 answers to exercises 139
7.2.2-28, which needs only 46 gigamems to discover all of the 1,787,056 unrestricted binary search
word squares; the double word squares are easily identified among those solutions. minimax
minimax
88. One could do a binary search, trying varying values of W. But the best way is to minimax
Flower Power
use the construction of exercise 87 together with the minimax variant of Algorithm C in Shortz
exercise 84. This works perfectly, when the options for most common words come first. Incroci Concentrici
Petal Pushers
Indeed, this method finds the double square ‘blast|earth|anger|scope|tense’
and proves it best in just 64 G^, almost as fast as the specialized method of exercise
7.2.2-28. (That square contains argon, the 1720th most common five-letter word, in
its third column; the next-best squares use peers, which has rank 1800.)
89. The “minimax” method of exercise 88 finds the first five squares of
HERTZES
CHESTS
SHOW START LUSTRE OPERATE
IS MAY NONE THREE OBTAIN MIMICAL
AGE ROOFS ACERATE
TO NOT OPEN ASSET ARENAS GENETIC
WEST CIRCLE
PEERS ASSESS ENDMOST
RESENTS
in respectively 200 K^, 15 M^, 450 M^, 25 G^, 25.6 T^. It struggles to find the best
6 x 6, because too few words are cut off from the search; and it thrashes miserably with
the 24 thousand 7-letter words, because those words yield only seven extremely esoteric
solutions. For those lengths it’s best to cull the 2038753 and 14513 unrestricted word
squares, which the method of exercise 7.2.2-28 finds in respectively 4.6 T// and 8.7 T^.
90. An XCC problem works nicely, as in answer 88: There are 2p primary items ai
and di for the final words, and pn + W secondary items ij and w for the cells and
potential words, where 0 < i < p and 1 < j < n. The Wp options going across are
‘ai i1:c1 i2:c2 . . . in:cn c1 . . . cn’. The Wp options going down are ‘di i1:c1 ((i+1) mod
p)2:c2 . . . ((i+n-1) mod p)n:cn c1 . . . cn’ for left-leaning stairs; ‘di i1:cn ((i+1) mod
p)2:cn-1 . . . ((i+n-1) mod p)n:c1 c1 . . . cn’ for right-leaning stairs. The modification
to Algorithm C in exercise 83 saves a factor of 2p; and the minimax modification in
exercise 84 hones in quickly on optimum solutions.
There are no left word stairs for p = 1, since we need two distinct words. The
left winners for 2 < p < 10 are: ‘write|whole’; ‘makes|lived|waxes’; ‘there|share|
whole|whose’; ‘stood|thank|share|ships|store’;‘where|sheep|small|still|whole|
share’; ‘makes|based|tired|works|lands|lives|gives’; ‘water|makes|loved|gives|
lakes|based|notes|bones’; ‘where |sheet|still|shall|white|shape|stars|while|
shore’; ‘there |shoes |shirt|stone|shook|start|while|shell|steel|sharp’. They
all belong to words(500), except that p = 8 needs words(504) for noted.
The right winners have a bit more variety: ‘spots’; ‘stall|spies’; ‘stood|holes|
leaps’; ‘mixed | tears | slept | salad’; ‘years | steam | sales | marks | dried’; ‘steps |
seals|draws|knots|traps|drops’; ‘tried|fears|slips|seams|draws|erect|tears’;
‘years|stops|hooks|fried|tears|slant|sword|sweep’; ‘start|spear|sales|tests|
steer|speak|skies|slept|sport’; ‘years|stock|horns|fuels|beets|speed|tears|
plant|sword|sweep’. They belong to words(1300) except when p is 2 or 3.
[Arrangements equivalent to left word stairs were introduced in America under
the name “Flower Power” by Will Shortz in Classic Crossword Puzzles (Penny Press,
February 1976), based on Italian puzzles called “Incroci Concentrici” in La Settimana
Enigmistica. Shortly thereafter, in GAMES magazine and with p = 16, he called them
“Petal Pushers,” usually based on six-letter words but occasionally going to seven. Left
July 26, 2019
140 answers to exercises 7.2.2.1
word stairs are much more common than the right-leaning variety, because the latter kernels
mix end-of-word with beginning-of-word letter statistics.] induced subgraph
in-degree
91. Consider all “kernels” c1 . . . c14 that can appear as il x1
out-degree
strong components
lustrated, within a right word stair of 5-letter words. Such x2 c1
kernels arise for a given set of words only if there are letters x3 x4 x5 c2 c3
x1 . . . x12 such that x3x4x5c2c3, c4c5c6c7c8, c9c10c11c12x6, c4 c5 c6 c7 c8
c13c14x7x8x9, x1x2x5c5c9, c1c2c6c10c13, c3c7c11c14x10, and c9 c10 c11 c12 x6
c13 c14 x7 x8 x9
c8c12x7x11x12 are all in the set. Thus it’s an easy matter to x10 x11
set up an XCC problem that will find the multiset of kernels, x12
after which we can extract the set of distinct kernels.
Construct the digraph whose arcs are the kernels, and whose vertices are the 9-
tuples that arise when kernel c1 . . . c14 is regarded as the transition
С1С2С3С4С5С6С7С9С10 ^ С3С7С8С9С10С11С12С13С14.
This transition contributes two words, c4c5c6c7c8 and c1c2c6c10c13, to the word stair.
Indeed, right word stairs of period p are precisely the p-cycles in this digraph for which
the 2p contributed words are distinct.
Now we can solve the problem, if the graph isn’t too big. For example, words(1000)
leads to a digraph with 180524 arcs and 96677 vertices. We’re interested only in the
oriented cycles of this (very sparse) digraph; so we can reduce it drastically by looking
only at the largest induced subgraph for which each vertex has positive in-degree and
positive out-degree. (See exercise 7.1.4-234, where a similar reduction was made.) And
wow: That subgraph has only 30 vertices and 34 arcs! So it is totally understandable,
and we deduce quickly that the longest right word stair belonging to words(1000) has
p = 5. That word stair, which we found directly in answer 90, corresponds to the cycle
A similar approach applies to left word stairs, but the kernel configurations are
reflected left-to-right; transitions then contribute the words c8c7c6c5c4 and c1c2c6c10c13.
The digraph from words(500) turns out to have 136771 arcs and 74568 vertices; but this
time 6280 vertices and 13677 arcs remain after reduction. Decomposition into strong
components makes the task simpler, because every cycle belongs to a strong component.
Still, we’re stuck with a giant component that has 6150 vertices and 12050 arcs.
The solution is to reduce the current subgraph repeatedly as follows: Find a
vertex v of out-degree 1. Backtrack to discover a simple path, from v, that contributes
only distinct words. If there is no such path (and there usually isn’t, and the search
usually terminates quickly), remove v from the graph and reduce it again.
With this method one can rapidly show that the longest left word stair from
words(500) has period length 36: ‘share|spent |speed |wheat|thank|child|shell |
SHORE|STORE |STOOD|CHART |GLORY|FLOWS |CLASS|NOISE |GAMES|TIMES |MOVES|BONES |
WAVES|GASES |FIXED|TIRED |FEELS|FALLS |WORLD|ROOMS |WORDS|DOORS |PARTY|WANTS |
which|where|shoes|still|state’, with 36 other words that go down. Incidentally,
glory and flows have ranks 496 and 498, so they just barely made it into words(500).
Larger values of W are likely to lead to quite long cycles from words(W). Their
discovery won’t be easy, but the search will no doubt be instructive.
92. Use 3p primary items ai , bi, di for the final words; pn + 2W secondary items ij ,
w, w' for the cells and potential words, with 0 < i < p and 1 < j < n (somewhat
as in answer 90). The Wp options going across are ‘ai i1:c1 i2:c2 . . . in:cn c1 . . . cn
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 141
с1 ... сП’. The 2Wp options going down in each way are ‘bi i1:c1 ((i+1) modp)2:c2 Mathews
. . . ((i+n-1) mod p)n:cn c1 . . . cn’ and ‘di i1:cn ((i+1) mod p)2:cn-1 . . . ((i+n-1) mod Brotchie
Oulipo
p)n:c1 c1... cn’. The items w' at the right of the ai options save us a factor of p. Flye Sainte-Marie
Use Algorithm C (modified). We can’t have p = 1. Then comes ‘spend |spies’; MRV heuristic
focus
‘waves | lined | leper’; ‘loops | pouts | trots | toons’; ‘spool | strop | staid | snort |
universal cycles
snoot’; ‘dimes|mules|riper|sired|aided|fined’; ‘miles|lints|cares|lamed|piped| ourotoruses
saner|liver’; ‘super|roved|tiled|licit|coded|roped|timed|domed’; ‘forth|lures|
mires|polls|slats|spots|soaps|plots|loots’; ‘times|furor|runes|mimed|caped|
PACED | LAVER| FINES |LIMED | MIRES’. (Lengthy computations were needed for p > 8.)
93. Now p < 2 is impossible. A construction like the previous one allows us again to
save a factor of p. (There’s also top/bottom symmetry, but it is somewhat harder to
exploit.) Examples are relatively easy to find, and the winners are ‘miles |galls|
bulls’; ‘fires | ponds | walks | locks’; ‘lives |fired | dikes | waved | tires’; ‘birds |
marks|poles|waves|wines|fonts’; ‘liked|wares|mines|winds|males|loves|fives’;
‘waxes|sites|mined|boxes|caves|tales|wired|males’; ‘cents|holds|boils|balls|
males|wines|finds|lords|cares’; ‘looks|roads|beats|beads|holds|cools|folks|
wines|gases|bolts’. [Such patterns were introduced by Harry Mathews in 1975, who
gave the four-letter example ‘tine|sale|male|vine’. See H. Mathews and A. Brotchie,
Oulipo Compendium (London: Atlas, 1998), 180-181.]
94. Set up an XCC problem with primary items k, pk , and secondary items xk , for
0 < k < 16, and with options ‘j pk xk:a x(k+1) mod 16:b x(k+3) mod 16:c x(k+4) mod 16:d’
for 0 < j, k < 16, where j = (abcd)2 . The solution (0000011010111011) is essentially
unique (except for cyclic permutation, reflection, and complementation). [See C. Flye
Sainte-Marie, L’Intermediate des Mathematiciens 3 (1896), 155-161.]
95. Use 2m primary items ak , bk , and m secondary items xk , for 0 < k < m. Define
m2 options of size 2 + n, namely ‘aj bk xj:t1 x(j+1) mod m:t2 . . . x(j+n-1) mod m:tn’,
where t1 t2 . . . tn is the kth binary vector of interest. However, save a factor of m by
omitting the options with j = 0 and k > 0, and the options with j > 0 and k = 0.
The case (7, 0, 3) has 137216 solutions, found in 8.5 gigamems; the case (7, 3, 4)
has 41280 solutions, found in 3.2 gigamems. (We can make the items bk secondary
instead of primary. This makes the search tree a bit larger. But it actually saves a
little time, because the MRV heuristic causes branching on aj and maintains a good
focus; less time is sp ent computing that heuristic when bk isn’t primary. Alternatively
we could make the items ak secondary (or even omit them entirely, which would have
the same effect). But that would be a disaster! For example, the running time for case
(7, 0, 3) would then increase to nearly 50 tera mems, because focus is lost.)
Section 7.2.1 discusses other “universal cycles,” which can be handled similarly.
96. In fact, there are 80 solutions for which the bottom four rows are the 00000110
complements of the top four. (This problem extends the idea of “ourotoruses” in 110
0101000101011
10001110
exercise 7.2.1.1-109. One can also consider windows that aren t rectangles. For 11111001
example, the thirty-two ways to fill a cross of five cells can be identified with 32 11101000
00110101
positions of the generalized torus whose offsets are (4, ±4); see exercise 7-137.) 01110001
97. Use primary items jk, pjk , and secondary items dj,k , for 0 < j < 3 and 0 <
k < 9, with the following three options for each 0 < i,j < 3 and 0 < k, k' < 9:
:
‘jk Pj'k' dj',k':i dj',k'+i:(i + a) dj'+i,k' :(i + b) dj'+i,k'+i (i + c)’, for 0 < j < 1, and
‘ jk P2k' d2,k':id2,k'+i:(i + a) do,k'-3:(i + b — 1) do,k'-2-(i + c — 1)’, where 9j + k = (аЬс)з;
sums involving i are mod 3, while sums involving k' are mod 9. We can assume that
00 is paired with p00. Then there are 2 • 2898 = 5796 solutions D; all have D = DT.
July 26, 2019
142 ANSWERS TO EXERCISES 7.2.2.1
98. Given a 3SAT problem with clauses (li1 V li2 V li3) for 1 < i < m, with each lij G 3SAT
{x1,X1,... , xn, xn}, construct an XCC problem with 3m primary items ij (1 < i < m,
all-different
stable extensions
1 < j < 3) and n secondary items xk (1 < k < n), having the following options: Bittencourt
(i) li1 li2 , li2 li3 , li3 li1 ; (ii) lij Xfc.1 if lij — Xk, lij Xk:0 if lij — Xk. That problem
has a solution if and only if the given clauses are satisfiable.
99. True — but perhaps with many more secondary items and much longer options:
Let x be a secondary item to which a color has been assigned, in some XCC problem A;
and let O be the options in which x appears. Replace A by a new problem A, by delet
ing item x and adding new secondary items x{o,p} for each o, p G O for which x gets dif
ferent colors in A. And for each o G O, replace item x in o by the set of all x{o,p} that ap
ply. If A' still involves colors, replace it by A” in a similar way, until all colors disappear.
100. (a) There are five solutions: 00112, 00122, 01112, 01122, 11111.
(b) Let there be five primary items, {#1, #2, #3, #4, #5}, and five secondary
items, {x1 , x2 , x3, x4, x5 }. Item #1 enforces the binary constraint x1 < x2 , and has
the options ‘#1 x1:0 x2:0’; ‘#1 x1:0 x2:1’; ‘#1 x1:0 x2:2’; ‘#1 x1:1 x2:1’; ‘#1 x1:1
x2:2’; ‘#1 x1:2 x2:2’. Similar options for #2, #3, and #4 will enforce the constraints
x2 < x3, x3 < x4, and x4 < x5. Finally, the options ‘#5 x1:0 x3:1 x5:2’; ‘#5 x1:0 x3:2
x5:1’; ‘#5 x1:1 x3:0 x5:2’; ‘#5 x1:1 x3:1 x5:1’; ‘#5 x1:1 x3:2 x5:0’; ‘#5 x1:2 x3:0 x5:1’;
‘#5 x1:2 x3 :1 x5 :0’ will enforce the ternary constraint x1 + x3 + x5 — 3.
(c) Use primary items #j for 1 < j < m, one for each constraint, and secondary
items xk for 1 < k < n, one for each variable. If constraint Cj involves the d variables
xi1 , . . . , xid , include options ‘#j xi1 :a1 . . . xid :ad’ for each legal d-tuple (a1 , . . . , ad).
(Of course this construction isn’t efficient for all instances of CSP; furthermore, we
can often find substantially better ways to encode a particular CSP as an XCC instance,
because this method uses only one primary item in each option. But the idea that un
derlies this construction is a useful mental tool when formulating particular problems.)
101. Notice that the final sentence implies two further clues:
• Somebody trains a zebra. • Somebody prefers to drink just plain water.
Let there be primary items #k for 1 < k < 16, one for each clue. And let the
5 • 5 secondary items Nj, Jj, Pj, Dj, Cj represent the nationality, job, pet, drink, and
color associated with house j , for 0 < j < 5. There are respectively (5, 5, 5, 5, 1, 5, 1, 5,
4, 5, 8, 5, 8, 8, 5, 5) options for clues (1, . . . , 16), typified by ‘#1 Nj :England Cj: red’,
for 0 < j < 5; ‘#5 N0:Norway’; ‘#9 Ci: white Ci+1:green’, for 0 < i < 4; ‘#14 Ji:nurse
Pi+1:fox’, ‘#14 Pi:fox Ji+1:nurse’, for 0 < i < 4; ‘#15 Pj:zebra’, for 0 < j < 5.
A more complex formulation enforces the redundant “all-different” constraint by
introducing 5 • 5 additional secondary items to represent the inverses of Nj , Jj , Pj , Dj ,
Cj. For example, the options for #1 then become ‘#1 Nj: England NE-ngland:j Cj:red
Cr-ed:j’. (With those additional items, Algorithm C will infer C1: blue immediately from
#5 and #11; but without them, #5 doesn’t immediately make N1:Norway illegal. They
reduce the search tree size from 112 to 32 nodes. However, the time they save during
the search just barely compensates for the extra time that they consume in step C1.)
The inverses alone are not sufficient; they don’t forbid, say, NE-ngland — NJ-apan .
[The author of this now-famous puzzle is unknown. Its first known publication, in
Life International 35 (17 December 1962), 95, used cigarettes instead of occupations.]
102. As in answer 7.2.2-68, let’s find all stable extensions of a given partially labeled
digraph. And let’s allow sinks too; we can assume that every vertex with out-degree
d < 1 is labeled d. The following XCC formulation is based on ideas of R. Bittencourt.
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 143
Let Д be the maximum out-degree. Introduce primary items Hv, Iv, Evd, and d+ (v): out-degree
secondary items v, hvd, ivd, for 0 < d < Д and all vertices v. The color of v will be A(v), pi day puzzle
Bittencourt
the label of v; the color of hvd will denote the Boolean quantity ‘[v sees d]’, meaning Lehmer
that A(w) = d for some w with v —>w; and the color of ivd will denote ‘[A(v) = d]’. The Gilbert
options for Hv are ‘Hv v:d Uto {hvk :ek }’ where e0 + • • • + ед = d. The options for Iv totient function ^
are ‘Iv v:d Ufe=0{ivk:[k = d]} Uu--v{hud:1}’• And the options for Evd are ‘Evd hvd:1
iwkd:1 Uk-Hiwjd:0}’ for 1 < k < d+(v) and ‘Evd hvd:0 Ud=(v){iwjd:0}’, when v —>wi,
... , v —> wd+(v). For example, if the vertices of the puzzle in exercise 7.2.2-68 are
named 00, . . . , 99, some of the options of its unique solution are ‘H00 00:3 h000:0 h001:0
h002 :0 h003:0 h004:1 h005:0 h006:0 h007:1 h008:0 h009:1’; ‘I00 00:3 i000:0 . . . i002:0 i003:1
i004:0 . . . i009:0 h013:1 h033:1 h053:1 h703:1 h803:1’; ‘E004 h004:1 i104:0 . . . i404:0 i504:1’.
Of course many of those options can be greatly simplified, because many of the
quantities are known from the given labels. We know the color of ivd when A(v) is
given; we know the color of hvd when v sees d in the given puzzle. We don’t need
Iv when v is labeled; we don’t even need Evd , when v is known to see d. If v has
out-degree d and already sees some label twice, we know that ivd is 0. And so on. In
the pi day puzzle such simplifications reduce 60 thousand options on 1200 + 1831 items
to 11351 options on 880 + 1216 items. That’s still a lot, and Algorithm C needs 135 M/
to input them; but then it finds the solution and proves it unique after 25 more M/.
(The highly tuned method of answer 7.2.2-68 needed only 7 M/ to prove uniqueness.
But that method solves only a small class of problems that happen to reduce nicely.)
Bittencourt notes that further speedup is possible when two arrows point in
the same direction. (This happens 123 times in the pi day puzzle.) In general if
v —>w implies u —>w, we must have A(u) > A(v); and this condition can be enforced
by introducing a new primary variable whose options allow u and v to have only
appropriate combinations of colors.
103. (a) An all-interval row always has xn-1 = (x0 + 1 + • • • + (n - 1)) mod n =
(x0 + n(n-1)/2) mod n = (x0 + [n even] n/2) mod n.
(b) Let j , pj , dk , qk be primary items and let xj be a secondary item, for 0 < j < n
and 1 < k < n. There’s an option ‘j pt xj :t’ for 0 < j, t < n, omitted when (j = 0 and
t = 0) or (j = n - 1 and t = n/2). And there’s an option ‘dk qt xt-1:i xt:(i + k) mod n’
for 1 < k, t < n and 0 < i < n. Then the tone row and its intervals are permutations.
There are (1, 2, 4, 24, 288, 3856) solutions for n = (2, 4, 6, 8, 10, 12). [These
values were first computed by D. H. Lehmer, Proc. Canadian Math. Congress 4 (1959),
171-173, for n = 12 and E. N. Gilbert SIAM Review 7 (1965), 189-198, for n < 12.]
For larger n, Algorithm C is not at all competitive with a straightforward back
track algorithm, which uses Algorithm 7.2.1.2X to find all suitable permutations of the
n- 1 intervals: That method needs only 100 M/ to find all 89328 solutions when n = 14,
compared to 107 G/ by Algorithm C! With backtracking we can generate all 2755968
solutions for n = 16 in 4.7 G/, and all 103653120 solutions for n = 18 in 281 G/.
(c) The intervals between adjacent classes in xQ are the same as those of x, except
that xk - xk-1 is replaced by x0 - xn-1. And we know that x0 - xn-1 = ±n/2.
(d) True; both are xk-1 . . . x0xn-1 . . . xk .
(e) The solution for n = 2 has every possible symmetry; and the solution x = 0132
for n = 4 is equivalent to xR, -xQ , and -xQR. For n = (6, 8, 10, 12) we can argue that
x can be equivalent to at most one of the 4<^(n) rows cx, cxR, cxQ, cxQR besides itself:
We can’t have x = cx when c =1. We can have x = cxR or cxQ only if c2 mod n = 1.
The fact that ct mod n = t has an odd number of solutions 0 < t < n shows that
July 26, 2019
144 ANSWERS TO EXERCISES 7.2.2.1
x = xR or x = —xQ are the only possibilities. A more complicated case analysis is Morris
necessary when analyzing solutions to x = cxQR; Gilbert stated incorrectly [page 196] Starr
primitive
that no such solutions exist. (He overlooked 12-tone rows such as 0 3 9 1 2 4 11 8 7 5 10 6, Lehmer
0149311 1085726, 01811 103957426, for which x = 5xQR. Similarly, the 20-tone Gilbert
disconnected
row 013112191391271418417168615510 satisfies x = 9xQR.)
Historical notes
At any rate, the transformations of (c) partition the solutions into clusters of size Ramos
2^(n) when there’s symmetry, 4^(n) when there’s not. Gilbert enumerated the cases of Gibat
Ouellet
symmetry when n < 12; R. Morris and D. Starr did it when n = 12 [J. Music Theory 18 Wonderword
(1974), 364-389]. For n = (6, 8, 10, 12, 14, 16, 18) the number of clusters with x = xR sharp preference
branch, choice of
turns out to be respectively (1, 1, 6, 22, 48, 232, 1872); the number of clusters with x =
choice of item to cover
—xQ turns out to be (0, 0, 2, 15, 0, 0, 1346); also n = 12 has 15 cases with x = 5xQR. Huang
Snyder
104. We may assume that x0 = 0. There’s a constant cr such that ykr = xk-1 + cr author
(modulo n) for 1 < k < n. Thus yr = xr-i = Cr; yr2 = x(r2-i) mod p = xr-i + Cr = 2cr; interactive method
yr3 = x(r3-1) mod p = x(r2-1) mod p + cr = 3cr; etc. Let r be primitive modulo p, so that
{r mod p, . . . , rn mod p} = {1, . . . , p — 1}, and let R = rd where Crd mod n = 1. Then
we’ve proved Rx(rk -1) mod p = (rk mod p) (modulo p) for 1 < k < n; that is, R xk-1 = k.
Now suppose xk — xk-i = xl — xl-i (modulo n). Then Rxk Rxl-1 = Rxk-1Rxl
(modulo p); consequently (k + 1) l = k(l + 1) (modulo p), hence k = l.
(b) x(n) = xR. [See the papers by Lehmer and Gilbert in answer 103.]
105. There are just five solutions; the latter two are flawed by being disconnected:
S T S T N E \V E S O N E I G H T N E I G H T
I W I W E V E KN I N N E \V E S) W N E \V E S) W
H V I X H V I X V L V R X E I \V\E) . E F I \V\E) . E
F
G H U E N L G H U E N L E E I G\H> T S O kN\Ext) L X O |<N\EXT) L
I T W O L V I T W O L V L W F .WT I W UEL V I W UEL V
E (E v I\F E V ~I F F E T (F (0/U R) X T H\R) EN E S T H\R) EN E
Historical notes: The earliest known word search puzzle was “Viajando” by Henrique
Ramos of Brazil, published in Almanaque de Selecoes Recreativas (1966), page 43. Such
puzzles were independently invented in America by Norman E. Gibat (1968). Jo Ouellet
of Canada developed “Wonderword,” which puts the unused letters to use, in 1970.
106. When Algorithm C is generalized to allow non-unit item sums as TH EE
107. To pack w given words, use primary items {Pij, RiC, CiC, BiC, #k | 1 < i, j < 9,
1 < k < w, c G {A, C, E, M, O, P, R, T, U}} and secondary items {ij | 1 < i, j < 9}. There
are 729 options ‘Pij Ric Cjc Bbc ij:c’, where b = 3|_(i — 1)/3j + [j/3], together with an
option ‘#k iiji:Ci . . . iljl :Cl’ for each placement of an l-letter word Ci . . . Cl into cells
(ii , ji), . . . , (il , jl). Furthermore, it’s important to use the sharp preference heuristic
(exercise 10) in step C3 of the algorithm.
A brief run then establishes that computer and corporate cannot RC
both be packed. But all of the words except corporate do fit together;
the (unique) solution shown is found after only 7.3 megamems, most of TI
which are needed simply to input the problem. [This exercise was inspired TP
E
by a puzzle in Sudoku Masterpieces (2010) by Huang and Snyder.] AR
108. (a, b) The author’s best solutions, thought to be minimal (but there is no proof),
are below. In both cases, and in Fig. 71, an interactive method was used: After the
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 145
longest words were placed strategically by hand, Algorithm C packed the others nicely. Gordon
Eckler
N (Y (E\L/N) I K C~M . . T N V
O . (CxOxO LID G^E . A L A
T 'S/^rXe/T) (r\A~C) "R Y O N
N L • JfrxNxAl\e\v E L C B
I A 'tX^CaXT O V W O N U
W L G R I C A M O R I R
A C J G A U L K D B H O L E
S E N E M L S A N H N
H F I H C R A M O M E O O
I R F D A R A N O N S X F S
N U E R Y E D HARR I S O N
G H R A E I 'Y D E N (n; Ф K R H
T T S H 1 P (G A R F I E~~ L D O
O R O '□/S EV E L T) . . O Y J
N A NJ/A H C U (B) U S H . P T
[Solution (b) applies an idea by which Leonard Gordon was able to pack the names of
presidents 1-42 with one less column. See A. Ross Eckler, Word Ways 27 (1994), 147;
see also page 252, where OBAMA miraculously fits into Gordon’s 15 x 15 solution!]
109. To pack w given words, use w + m(n — 1) + (m — 1)n primary items {#k | 1 <
k < w} and {Hij, Vij | 1 < i < m, 1 < j < n}, but with Hin and Vmj omitted; Hij
represents the edge between cells (i, j) and (i, j + 1), and Vij is similar. There also are
2mn secondary items {ij,ij' | 1 < i < m, 1 < j < n}. Each horizontal placement of
the kth word c1 . . . cl into cells (i, j + 1), . . . , (i, j + l) generates the option
with 3l + 4 items, except that ‘ij:. ijz:0’ is omitted when j = 0 and ‘i(j+l+1):.
i(j+l+1)/:0’ is omitted when j+1 = n. Each vertical placement is similar. For example,
#1 11:Z 11':1 V11 21:E 21':1 V21 31:R 31':1 V31 41:O 41':1 51:. 51':0 (*)
is the first vertical placement option for zero, if zero is word #1. When m = n,
however, we save a factor of 2 by omitting all of the vertical placements of word #1.
To enforce the tricky condition (ii), we also introduce 3m(n — 1) + 3(m — 1)n
options:
Important: As in answer 107, the sharp preference heuristic should be used here, sharp preference heuristic
because it gives an enormous speedup. McDonald
Gordon
The XCC problem for our 11-word example has 1192 options, 123 + 128 items,
and 9127 solutions, found in 29 G//. But only 20 of those solutions are connected; and
they yield only the three distinct word placements below. A slightly smaller rectangle,
7 x 9, also has three valid placements. The smallest rectangle that admits a solution
to (i) and (ii) is 5 x 11; that placement is unique, but it has two components:
FF F TWO FIVE ET
ZERO SIX ONE S TWO I FIVE SIX F SIX F T
IU V U NINE UG G NI NE O NE E I GHT
G R TEN ZERO V ZERO H H VF U VT V RT
H HI IFE N TEN TWO ZERO R EE E EW
TWO R N G SIX N SEVEN I
NEE HV IN N NU NINE ZERO
SEVEN THREE X THREE THREE R
Instead of generating all solutions to (i) and (ii) and discarding the disconnected
ones, there’s a much faster way to guarantee connectedness throughout the search; but
it requires major modifications to Algorithm C. Whenever no H or V is forced, we can
list all active options that are connected to word #1 and not smaller than choices that
could have been made earlier. Then we branch on them, instead of branching on an
item. For example, if (*) above is used to place ZERO, it will force H00 and H20 and
V30. The next decision will be to place either eight or one, in the places where they
overlap zero. (However, we’ll be better off if we order the words by decreasing length,
so that for instance #1 is eight and #11 is one.) Interested readers are encouraged to
work out the instructive details. This method needs only 630 ,\l// to solve the example
problem, as it homes right in on the three connected solutions.
110. Gary McDonald found this remarkable 20 x 20 solution in 2017:
WILSON TAFT P
I A O C JO HNSON
X YRLE L
T H COO LIDGE F AK
REAGAN O VF R
URR ROOSEVEL T
MRTB BLR HAYES
AIEU ADAMS UI
NSRC MNO RS
OH HARDING E
NA O GRANT
F MON ROE J H
IA V WASHI NGTON
L MCKIN LEY C AW
LL R K PI ERCE
MADISON BUSH FR
ON O I
R TYLE R VAN BU REN
EO L
LINCOLN KENNEDY
Algorithm M handles case (b) with ease (5 Gp). But it does not explore the space of backtracking program
possibilities for case (a) intelligently, and costs 591 Gp. WORDS(5757)
Bittencourt
112. (a) Yes: immature, maturing, commuter, grouping, trouping, authoring, and Bittencourt
MCC problem
thrumming. A straightforward backtracking program will quickly determine the pres- covering problem
ence or absence of any given string of letters. XCC problem
(b) Let’s put dancing and links in there too. Then we obtain an array CGN Break symmetry
NIK
with 24 words from words(5757) (like lover, rosin, salvo, toads, trove); LAS
also asking, dosing, losing, ordain, sailor, signal, silver; also lancing, VOD
ERT
loaning, soaking, and even ortolan. (Notice that torto occurs in two ways.) TOW
To find such arrays, as suggested by R. Bittencourt, we can let word k be
c0 ... ct-1, and introduce primary items Wkl for 1 < l < t to represent the placement
of cl-1cl. Let Xu be a secondary item, for each cell u of the array, to be colored with
some letter. Represent the king path for word k by giving color u to Pkl and color l
to Qku when cl is in cell u, where Pkl and Qku are additional secondary items. There
also are secondary items Dkv , for each internal vertex v . For example, if the cells and
vertices are numbered rowwise, two of the options chosen for dancing and links in the
example above are ‘W03 X3:N X0:C P02:3 P03:0 Q03:2 Q00:3’ and ‘W12 X4:I X2:N P11:4
P12:2 Q14:1 Q12:2 D11 ’. The ‘D11 ’ in the latter will prevent another step of word 1
between cells 2 and 4.
We can save a factor of nearly 4 by restricting the placement of, say, cl-1cl in
word 0 when l = [to/2j, so that cl-1 lies in the upper left quadrant and cl isn’t in the
rightmost column. Then W0l has only 26 options instead of the usual 94.
It turns out that exactly 10 essentially different Torto arrays contain dancing,
links, torto, words, and solver; exactly 1444 contain the, art, of, computer, and
PROGRAMMING. They’re found by Algorithm C in 713 Gp and 126 Gp, respectively.
(c) Yes, in 140 ways (but we can’t add eleven). Similarly, we can
FXN FSX ETV
pack zero, one, . . . , up to eight, in 553 ways. And first, . . . , sixth SIN ZIE FHX
can be packed in 72853 ways, sometimes without using more than 16 GEV GEV FIT
HRE HRN ORS
of the 18 cells. (These computations took (16, 5, 1.5) Tp. Interesting UTN TOU UDE
words lurk in these arrays — can you spot them? See Appendix E.) FOW WNF NOC
potential sets of letters has five options of size 23, showing exactly which letters are Riekstins
present if block j uses that set; for example, the five options for {A, B, C, D, E, I} are ‘j Castawords
Russell
Aj :1 ... Ej :1 Fj:0 ... Ij:1 ... Yj :0’ for 1 < j < 5. There are 18486 options altogether, Michel
of total length 403357; Algorithm C solves them in 225 G^. Alon
Mycielski
For these words the five blocks must be {E, F, G, L, O, S}, {C, E, T, R, U, Y}, {A, L, M, Sachs
N, Q, R}, {A, B, E, P, S, T}, {D, H, K, T, U, V}. (The XCC problem actually has 8 solutions,
because times, trees, and value can each be formed in two ways from those blocks.)
[This exercise is based on an idea by E. Riekstins, who realized that a classic
puzzle called Castawords could be extended to words of length 5.]
114. Besides the primary items pij, rik, cjk, bxk of (30), introduce Rik, Cjk, and Bxk
for the permuted array, as well as uk and vl to define a permutation. Also introduce
secondary items nk to record the permutation and ij to record the value at cell (i, j).
The permutation is defined by 81 options ‘uk vl nk:l’ for 1 < k, l < 9. And there are
94 = 6561 other options, one for each cell (i, j) of the board and each pair (k, l) of
values before and after a is applied. If (ij)a = i'j', let x' = 3|_i'/3j + Lj//3J. Then
option (i,j, k,l) is normally ‘pij rik Cjk bxk Ri/l Cj/l Bx/l ij:k i'j':l nk:l’. However, if
i = i and j = j, that option is shortened to ‘pij rik cjk bxk Ril Cjl Bxl ij:k nk :l’; and
it is omitted when i = i, j = j, k = l. The options (0, j,k,l) are also omitted when
k = j + 1, in order to force ‘123456789’ on the top row.
With that top row and with a = transposition, Algorithm C produces 30,258,432
solutions in 2.2 teramems. (These solutions were first enumerated in 2005 by E. Russell;
see www.afjarvis.staff.shef.ac.uk/sudoku/sudgroup.html .)
115. A similar method applies, but with additional items b'yk and B'y,l as in answer
67(b). The number of solutions is (a) 7784; (b) 16384; (c) 372; (d) 32. Here are
examples of (a) and (d); the latter is shown with labels {0, . . . , 7, *}, to clarify its
structure. [Enumerations (a), (b), (c) were first carried out by Bastian Michel in 2007.]
1 2 3 4 5 6 7 8 9 7 0 2 5 1 3 * 4 6
9 7 4 3 1 8 5 6 2 5 3 6 * 7 4 2 0 1
8 5 6 9 7 2 1 3 4 * 1 4 2 0 6 7 5 3
5 8 2 1 3 9 4 7 6 2 5 7 0 6 1 3 * 4
4 1 7 8 6 5 2 9 3 (d) 0 4 3 7 * 5 1 6 2
6 3 9 2 4 7 8 5 1 6 * 1 3 4 2 5 7 0
7 4 1 5 9 3 6 2 8 1 7 5 4 2 0 6 3 *
3 6 8 7 2 4 9 1 5 3 2 0 6 5 * 4 1 7
2 9 5 6 8 1 3 4 7 4 6 * 1 3 7 0 2 5
116. (a) Any triangle in ^(G) must be in G, because u' —- v'.
(b) Suppose ^(G) can be c-colored with some coloring function a, where a(w) = c.
If a(v) = c for any v G V, change it to a(v'). This gives a (c — 1)-coloring of G.
[Hence a triangle-free graph on n vertices can have chromatic number Q(log n). One
can show nonconstructively that the triangle-free chromatic number can actually be
Q(n/log n)1/2; but currently known methods of explicit construction for large n achieve
only Q(n1/3). See N. Alon, Electronic J. Combinatorics 1 (1994), #R12, 1-8.]
(c) If G is x-critical, so is ^(G): Let e G E and suppose a is a (c — 1)-coloring
of G \ e. Then we get c-colorings of all but one edge of ^(G) in several ways: (i) Set
a(v') ^ c for all v G V, and a(w) ^ 1. (ii) Let u G e, and set a(u) ^ a(w) ^ c; also
set a(vz) = a(v) for all v G V, either before or after changing a(u). If you want to
remove an edge of ^(G) that’s in G, use (i); otherwise use (ii).
[See J. Mycielski, Colloquium Mathematicum 3 (1955), 161-162; H. Sachs, Ein-
fuhrung in die Theorie der endlichen Graphen (1970), §V.5.]
July 26, 2019
7.2.2.1 answers to exercises 149
117. (a) Use the answer to (b), with each clique consisting of a single edge. Monte Carlo
(b) Each vertex v has d options ‘v c1j ... ckj’ for 1 < j < d, where the cliques modified Algorithm C
symmetry
containing v are {c1 , . . . , ck}. intersection
(c) We save a factor of 9! = 362880 by fixing the colors of the queens in the top torus
supertile
row. Then there are 262164 solutions, found by Algorithm X in 8.3 Tu with method (a)
but in only 0.6 T^ with method (b).
(d) Insert ‘v':j’ into the jth option for v, where v' is secondary. (This reduces
the running time for method (a) in part (c) to 5.0 Tu, without fixing any colors.)
(e) Using (d) to save a factor of c!, we get (2!• 1, 3!• 5, 4!• 520, 5!• 23713820) solutions,
in approximately (600, 4000, 130000, 4100000000) mems. [Monte Carlo estimates can
be made for larger cases by combining exercises 86 and 122; the true branching factor
at each level can be determined by rejecting options that involve illegal purification. It
appears that M6 can be 6-colored in approximately 6! • 2.0 x 1017 ways.]
(f) Now (d) saves a factor of (c-1)!, despite having no solutions; the running times
are roughly (100, 600, 5000, 300000) mems. (But then for 5-coloring M6 it’s 45 Tu!)
(g) There are (1! • 1, 2! • 1, 3! • (5 or 7), 4! • (1432, 1544, 1600, 2200, 2492, 2680,
3744, 4602, or 6640)) such colorings, depending on which edge is deleted.
118. In general, colorings of a hypergraph can be found with the
ABCDCDAB
construction of the previous exercise, but using Algorithm M and giv BDBDCACA
ing multiplicity [0 . . (r-1)] to each hyperedge of size r. In this case, CBACDBAD
however, there are 380 independent sets of size 16 (see exercise 7.1.4 DDABABCC
242); we can simply use them as options to an exact cover problem AADCDCBB
with 64 items. There are four solutions, having a curious symmetry so BCDBACDA
that only two are “essentially different”: One is shown, and the other CACABDBD
is obtained by keeping A and C fixed but transposing the B’s and D’s. DCBABADC
119. Exactly three interior edges are white in every solution. Any other placement of
the all-white piece defines those three edges. That leaves no way to place all three of
the two-white pieces.
120. (a) Call the types 0, 1, . . . , 9, and use Algorithm C to find all ways to place a
given type at the center of a 5 x 5 array. There are respectively (16, 8, 19, 8, 8, 8, 10, 8,
16, 24) ways to do this; and the intersection of all solutions for a given type shows that
????? 0490? ????? 68568 21721 32032 2032? 49049 0320? 17217
????? 2032? ??0?? 0490? ?6856 17217 ?217? 0320? 21721 68568
??0?? , ?217? , ??2?? , 2032? , 9049? , 68568 , 8568? , 21721 , ?6856 , 049?
??2?? 8568? ????? ?217? 320?? 049?? 490?? ?6856 9049? 20??
????? 490?? ????? 8568? 172?? 20??? 032?? 9049? 320?? ?2??
are the respective neighborhoods that are forced near a given type in any infinite tiling.
Consequently every such tiling contains at least one 5; and if we place 5 at the origin
everything in the entire plane is forced. The result is a torus in the sense of exercise
7-137, with a periodic supertile of size 12:
OrX’X’X’nrX’XTnX’X’X’X’JX’XTrX’X’Xl
F3MF1MF1MF1MFFJMFJMFJMF3MFF3MF1MF1MFJWFFJMFJMF3MF3MF3MF1
► ”■> ”■> ”■> ”■> ► ► ”■> ”■> ”■> ”■> ► '"ЛЬ J
ж ’ж 3
(b) Similarly, there’s again a unique tiling, this time with a 13-cell supertile:
к JFJk JBF’' <F <F JFJk JBF’’ <F <F 3F> JBF’' <F <F JFJk JBF’ <F <F 3FJ
«□UF I 3BF- <OMF I JA JBF” <Оы» 3F^ JOF’ <F <F I JBF” <OMB
^■F- <F <F 3F Jk JBF’’ <F <F JF^ JiFT < ^F JF Jk JHF'' <F <F JFMT''
I AT AT I AT AT I AT AT I AT AT I JA-
T AT J ЛА- AT AT 2 JA AT AT J ЛА ^A AT AT 2 JA JA AT AT
UT'' <■><■> 1ТЛА MT'' <ВМИ> 1ТЛА MT'' <■><■> 3FJ» MT'' <ВМИ> -ЯТЛА MT'' <
121. (a) Marek Tyburec noticed in 2017 that there are no 2 x 2 solutions with eUS at Tyburec
lower right; similarly, there are no 3 x 4 solutions with eUS at lower left. Hence eUS dragon sequence
threshold
can appear only in the top row, or at the left of the next-to-top row. CTH
(b) Let (Ak, Bk,Ck, Dk) be the (2k — 1) x (2k — 1) tilings defined by (aa, ab, ac, ad) purify
unpurify
when k =1, otherwise by placing (3Na,3Nb,3Nc,3Nd) in the middle and placing commit
Ak-1, Bk-1, Ck-1, Dk-1 at the corners as in answer 2.3.4.3-5. The unique tiling uncommit
requested here has 3RD in the middle and Dk-1, Ck-1, Bk-1, Ak-1 at the corners. restricted growth strings
m x n parallelogram
(c) With 3RU or 3LD in the middle, another solution has Ck-1, Dk-1, Ak-1, Cartesianwise
Bk-1 at the corners. With 3LU or 3SU, there’s a third solution with Bk-1, Ak-1, parallelogram
barycentric
Dk-1, Ck-1 at the corners. And 3SU also has 54 additional solutions with Ck-2 in the coordinates
upper left corner; they use {DL, DP, DS, DT, UL, UP, UR, US, UT } in the upper half
when choices need to be made, and independently {R, YR, L, P, S, T } in the lower half.
(d) Only one of each survives. As in (b), its four quadrants are Dw, Cw, Bw, Aw.
[Each of the other 86 types occurs in A6, hence in every sufficiently large tiling.
Incidentally, the “dragon sequence” (see answer 4.5.3-41) arises in the colors at the
edges of A<. B .-., CW , D ...|
122. A new global variable 0, initially v, is the current “color threshold.” Every item
has a new field cth in addition to name, llink, and rlink. That field is normally
zero in primary items, although it has a special use in step C3 as described below. In
secondary items, cth will be used to undo changes to 0.
Insert ‘CTH(i) ^ 0; if c = 0, set 0 ^ 0 + 1’ just after ‘i ^ TOP(p)’ in the
purify routine (55). Insert ‘0 ^ CTH(i)’ just after ‘i ^ TOP(p)’ in the unpurify
routine (57). Modify the commit routine (54) so that it jumps to the end of the
uncommit routine (56), if COLOR(p) > 0, without changing j or p. (The effect is to
avoid committing to any option that would have set a color value greater than 0, by
jumping from step C5 into the appropriate place within step C6.
*)
Finally, change step C3 so that it never chooses an item i for which cth(i) > 0.
That step should then go to C8 if no item is choosable. (This mechanism prohibits
branching on primary items for which the assumption of total symmetry between all
colors > 0 isn’t yet valid. Exercise 126 has an example.)
123. When, say, m = 4 and n = 10, Algorithm C takes 49 megamems to produce
1048576 solutions. The modified algorithm (where we set v = 1) takes 2 megamems to
produce 43947 solutions. (Notice that the value vectors q1 . . . qn are equivalent to the
restricted growth strings a1 . . . an of 7.2.1.5-4, with qk = ak + 1.)
124. Let (x,y) denote a Д triangle, and let (x,y)' denote the V triangle that lies
immediately to its right. (Think of a square cell (x, y) that has been subdivided into
right triangles by its main diagonal, then slanted and yscaled by 3/2.)
For example, an m x n parallelogram has 2mn triangles (x, y) and (x, y)'
for 0 < x < m and 0 < y < n, Cartesianwise; the 3x2 case is illustrated.
The boundary edges of triangle (x, y) are conveniently denoted by /xy , \xy,
and -xy. Then the boundary edges of (x,y)' are /(x+1)y, \xy, and -x(y+1).
[A “barycentric” alternative with three coordinates is also of interest, because it’s
more symmetrical: Each triangle corresponds to an ordered triple of integers (x, y, z)
such that x + y + z = 1 or 2, under the correspondence (x, y) о (x, y, 2 — x — y) and
* Backtrack programs often run into such cases where it is permissible, even desirable, to
jump into the middle of a loop. See Examples 6c and 7a in the author’s paper “Structured
programming with go to statements,” Computing Surveys 6 (1974), 261—301.
(x,y)' о (x,y, 1 — x — y). The twelve symmetries are then the six permutations of dihedral group
{x, y, z} with an optional flip between (x, y, z) and (x, y, z) = (1 — x, 1 — y, 1 — z).] even/odd coordinates
Gottfried
[One can also use “barycentric even/odd coordinates,” inspired by exercise 145, MacMahon
which are ordered triples (x, y, z) with |x + y + z| < 1. Cases with x, y, z odd represent symmetries
Monte Carlo
triangles, with (x, y) о (2x — 1, 2y — 1, 3 — 2x — 2y), (x, y) о (2x — 1, 2y — 1,1 — 2x — 2y).
Cases with x, y , z even represent vertices. Cases with just one even coordinate represent
edges (the average of two adjacent triangles). Cases with two even coordinates could
represent directed edges.]
125. Every original triangle (x,y) or (x,y)' expands to k2 triangles of the forms
(kx + p, kx + q) or (kx + p', kx + q')' for 0 < p, q,p', q' < k. Those obtained from (x, y)
have p + q < k and p + q' < k — 1 (of which there are (k^1) and (2), respectively). The
others are obtained from (x,y)'.
126. Let there be 24 primary items 01’, 02, 02’, . . . , 32 for the triangles, and 24
primary items aaa, aab, . . . , ddd for the tiles, together with 42 secondary items \01,
-02, /02, ... , /41 for the edges. There are 24 • 64 options ‘01’ aaa -02 :a /11:a \01: a’,
‘01’ aab -02:a /11:a \01:b’, ‘01’ aab -02:a /11:b \01:a’, . . . , ‘32 ddd -32:d /32:d
\32:d’ — one for each way to place a tile. Finally, to force the b oundary conditions,
add another primary item ‘*’, and another option ‘* -20:a -30:a /40:a . . . \10:a’.
Algorithm C finds 11,853,792 solutions, after 340 G// of computation; this total in
cludes 72 different versions of every distinct solution, hence there really are just 164,636
of them (a number that was unknown until Toby Gottfried computed it in 2001).
Using exercise 119 we can remove all options for aaa except ‘20 aaa -20:a /20:a
\20:a’. Algorithm C then finds 11853792/12 = 987,816 solutions, in 25 G//.
Furthermore, using exercise 122 (with v = b), and not allowing step C3 to branch
on a tile name until 0 = e (because there’s total symmetry with respect to triangle
locations but not tile names), finds every distinct solution just once, in 6.9 G//.
Finally, we can allow branching on aab whenever 0 > c, and in general on a piece
name whenever 0 exceeds all colors in its name. This reduces the runtime to 4.5 G//.
[MacMahon specifically designed pattern (59b) to include all three of the nonwhite
solid-color triangles in the center. If we fix them in those positions, an unmodified
Algorithm C quickly finds 2138 solutions. There also are 2670 solutions with those
three fixed in positions {11’, 21’, 12’} instead of {12, 21, 22}.]
127. Every color appears in (3 • 24)/4 = 18 places among the triangles, hence 18 — 2k
times on the border when it occurs k times in the interior of a solution. Consequently no
color occurs an odd number of times on the border. That leaves 2099200 possibilities.
All of those 2099200 are actually completable. (MacMahon would have been very
happy to have known this!) The number of cases can be reduced to only 4054, using the
methods of Section 7.2.3, because there are 576 symmetries: cyclic shifting and/or re
flection and/or permutation of colors. The Monte Carlo procedure of Algorithm 7.2.2E
not only finds solutions in each of those cases, it finds oodles of them. In fact, we can
be confident that every all-even-but-not-constant border specification has more than
four times as many solutions as the pure-white border does.
(More precisely, the pure-white border 000000000000 has 11853792 solutions,
without reducing by symmetry; the next-smallest border, 000000000011, has 48620416;
the next-smallest, 000000000101, has 49941040; and so on. There are more than 100
million solutions in the vast majority of cases, but probably never more than 500
million. Incidentally, 001022021121 is the only valid color pattern that has exactly
three automorphisms.)
July 26, 2019
152 answers to exercises 7.2.2.1
128. We can pack them into the 11-triangle region obtained by deleting triangle (2,1)' supertile
from the 2 x 3 parallelogram in answer 124, in such a way that the edge colors satisfy tiles the plane
-00 = -20, /01 = /30, -02 = -12. There are 1032 ways to do this, one Ж'бЖ'г/'К
of which is shown. This yields a “supertile” that nicely tiles the plane,
in combination with its 180° rotation:
129. First consider rotation symmetry. Only 180° rotation applies, because of the four
single-color tiles. To generate all of the strong solutions, assume that rotation changes
a о d, b о c, and combine the options of answer 126 into pairs such as ‘02 abc -02:a
/02:b \02:c 31’ bdc -32:d /41:c \31:b’. The resulting 768 options have 68,024,064
solutions (found in about 0.5 T^); but many of those solutions are essentially the same
(that is, obtainable from each other by rotation, reflection and/or color permutation).
It’s somewhat tricky to count the essentially distinct patterns; canonical repre
sentations can be obtained by distinguishing six types of solutions: (1) 02 aaa (hence
31’ ddd) and 03 bbb (hence 30’ ccc), and /12:a or /12:c. [The cases /12:b or /12:d are
equivalent to these, if we reflect and swap a о b, c о d.] (2) 02 aaa, 23 bbb [or equiva
lently 03’ bbb]. (3) 02 aaa, 13’ bbb, and \03:a or \03:c. (4) 02 aaa, and bbb in 12, 12’,
22, 22’, or 13. (5) 13 aaa, 02’ bbb, and \12:a or \12:c. (6) 13 aaa, 12 bbb. Each type
is easy, yielding 80768 + 164964 + 77660 + 819832 + 88772 + 185172 = 1417168 solutions.
[Notice that the illustrated example of strong symmetry actually tiles the plane
without rotation; that is, it has -04 = -20, -14 = -30, /03 = /41, . . . , \10 = \32.
Exactly 40208 of the essentially distinct solutions satisfy this additional proviso.]
To generate the weak solutions, introduce new secondary items bxy, b'xy for each
triangle (x,y) or (x,y) with y > 1, representing color changes within the triangle.
Typical options are now ‘02 aad -02:a /02:a \02:d b02:5’, ‘02 aad -02:a /02:d \02:a
b02:3’, ‘02 aad -02:d /02:a \02:a b02:6’, ‘02 abc -02:a /02:b \02:c b02:7’, ‘31’
bdc -32:c /41:b \31:d b02:7’, ‘31’ ccd -32:c /41:c \31:d b02:5’. We may assume
that ddd is opposite aaa, ccc is opposite bbb. Algorithm C generates each weak-
not-strong solution twice, each strong solution once; the six types yield a total of
24516 + 45818 + 22202 + 341301 + 44690 + 130676 = 609203 weak-not-strong solutions.
Turning now to reflections of the hexagon, there are two essentially different
possibilities: Top-bottom reflection preserves the values of four edges, but all triangles
change; left-right reflection preserves the values of four triangles and two edges. There
fore strong reflection symmetry is impossible. (In the first case, all triangles change,
hence all colors change. In the second case, two colors must be fixed. With colors a and
d fixed but b о c, eight triangles aaa, aad, abc, acb, bcd, bdc, dda, ddd must be fixed.)
Weak symmetry under top-bottom reflection can be assumed as before to take
aaa to ddd, bbb to ccc. Again there are six types: [1] 02’ aaa, 22’ bbb, -13:a or -13:c.
[2] 02’ aaa, bbb in 12’, 03’, 13, 13’, or 23. [3] 12’ aaa, bbb in 03 or 03’. [4] 03 aaa,
23 bbb, 13:a or -13:c. [5] 03 aaa, bbb in 13 or 13’. [6] 03’ aaa, 13’ bbb, -13:a or -13:c.
Surprisingly, some placements are “special”: They have strong rotational symmetry,
as well as weak top-down symmetry! Algorithm C, which generates the special ones
once and the others twice, produces respectively (88, 0, 0, 98, 0, 75) + 2(1108, 12827,
8086, 3253, 12145, 4189) solutions. Here are examples of the 88+ 98+ 75 = 261 special
July 26, 2019
7.2.2.1 answers to exercises 153
placements, which belong simultaneously to types [1] and (5), [4] and (3), [6] and (1): Jones
Multimatch®
coordinate system
symmetries
contact system for adjacent tiles
dihedral group
chirality
reflection
anti-wave
Weak left-right symmetry is similar, but there now are some fixed triangles. If flipped over
Kadon Enterprises
aaa is fixed, assume that ddd is also fixed; three such types arise, with 46975 + 35375 + Trifolia®
25261 = 107611 solutions. Otherwise assume that ddd is opposite aaa; six types of this
kind yield (75, 0, 98, 0, 0, 88) strong and (3711, 56706, 5889, 60297, 38311, 9093) non
strong solutions. So there’s a grand total of 281618 essentially distinct weak-not-strong
placements with left-right symmetry — of which 194 are top-down symmetric too.
[Arrangements that have strong and weak symmetry were first discovered by
Kate Jones, who presented them in the 1991 user manual for Multimatch1® III, an
attractively produced set of triangular tiles.]
130. The nicest coordinate system for an octahedron is probably to number the faces
000, 001, . . . , 111 in binary, and to let the vertices be {**
0 , **
1 , *
0 , *
1 , ** 1 };
0 , **
the edges are {xy*,x*y, *xy} for x,y G {0,1}. Construct 512 options ‘000 aaa * 00:a
*:a
0 :a
*
00 ’, ‘000 aab *
00:a * 0:b *
:a
00 ’, ‘000 aab *
00:b *0:a :a
*
00 ’, . . . , with
face-name items 000, . . . , 111 primary and tile-name items aaa, . . . , ddd secondary.
Algorithm C quickly finds 2723472 solutions, which include 45356 distinct sets of eight.
Those 45356 sets become, in turn, new options for Algorithm X (or C), with 24 primary
tile-name items; now we get 1615452 solutions, which are the desired partitions.
Many symmetries are present, of course; we’ll study how to distinguish noniso
morphic representatives in Section 7.2.3. One of the most interesting solutions,
has four color-swap symmetries, with all the solid-color triangles on one octahedron.
131. (a) Each triangle edge is either a (straight) or b (a wave) or c (a hump) or
d (a dip). We can set this up with options and items as in answer 126, except that the
edge-match condition is now a ^ a, b ^ b, c ^ d, d ^ c; to get proper matching, the
options of V triangles should state the mate color, as in ‘01’ abc -02:a /11:b \01:d’.
Every solution corresponds to 24 equivalent solutions, because we get a factor
of 6 by rotating the hexagon, a factor of two by interchanging humps with dips, and
another factor of two by reflection. (Reflection is a bit tricky, because a wave becomes
an anti-wave when a piece is flipped over. However, every reflected piece has its own
anti-piece, which yields the desired anti-solution.) Thus we can force aaa to be in
position 02. Treating c and d symmetrically as in answer 126 (with v = c) produces
exactly 2,231,724 canonical solutions and needs only 30 gigamems of running time.
[This puzzle is manufactured by Kadon Enterprises under the name Trifolia®.]
(b) A similar setup, letting c and d represent 0 spots and 3 spots so that it’s easy
to treat them symmetrically, now has mates a ^ b, b ^ a, c ^ d, d ^ c; hence one
option is ‘01’ abc -02:b /11:a \01:d’. The boundary colors in directions / and \ are a;
in direction - they are b. The solutions to this problem typically form groups of eight
(not 24): We can swap c о d, reflect left-right, reflect top-down, or rotate by 180°;
July 26, 2019
154 ANSWERS TO EXERCISES 7.2.2.1
the latter two are combined with swapping a о b. Without attempting to remove any 180° rotation
symmetries, we get 3,419,736,176 solutions, after 20.6 teramems of computation. Burnside’s lemma
Esser
Left-right reflection always gives a distinct solution, whether we swap c о d or not Diophantine equation
(because there are at least eight pieces that stay fixed, and only four places to put them). Smart
history
But the illustrated example shows that some solutions are fixed under 180° rotation; we O’Beirne
can find them by adding 15 new primary items, such as #/23, and 15 • 4 new options, Stanford Artificial Intelligence Laboratory
such as ‘#/23 /23:x /20:x’ for x G {a,b, c, d}. Altogether 18656 solutions have that Feldman
Fernandez Long
symmetry; such cases form groups of four, not eight. Similarly, 169368 cases turn out even/odd coordinates
to have top-down symmetry. It follows from “Burnside’s lemma” that the total number odd/even coordinates, see even/odd
of essentially different solutions is (3419736176 + 18656 + 169368)/8 = 427490525. Jones
Multimatch®
To double the speed of all these computations, take v = c in exercise 122. Monte Carlo estimates
Fink
132. This challenging problem was first resolved by Peter Esser in April 2002, and pre Risueno
sented online at www.polyforms.eu/coloredpolygons/triindex.html#trios24 . [See Philpott
JRM 9 (1977), 209. One can show that the only solutions to the Diophantine equation even/odd coordinate system
d+ d(d-1) + d(d-1)(d-2)/3 = m2 are d = 1, 2, and 24, using advanced methods found
in N. P. Smart, The Algorithmic Resolution of Diophantine Equations (1998).]
133. This problem is like exercise 126, but considerably simpler because squares are
easier than triangles. There are 24 • 81 options ‘00 aaaa h00:a v10:a h01:a v00:a’,
. . . , ‘53 ccba h53:a v63:c h54:c v53:b’, where hxy and vxy denote the horizontal and
vertical edges between squares. We save a factor of 4 by limiting aaaa to four positions
on the border, and another factor of 2 by making b and c equivalent (exercise 122 with
v = b). The resulting 13328 solutions are found in 15 G//.
[Today it’s easy to count them; but this problem has a tortured history! T. H.
O’Beirne missed two of the 20 possible ways to place the internal white edges, when he
analyzed the situation by hand in New Scientist 9 (2 February 1961), 288-289. A few
years later, the problem of solution counts for MacMahon squares was probably the very
first large computation ever undertaken at Stanford Artificial Intelligence Laboratory;
Gary Feldman found 12261 placements, during a 40-hour computer run (see Stanford AI
Project, Memo 12 (16 January 1964), 8 pages). That number was believed to be correct
until May 1977, when the true value was obtained by H. Fernandez Long in Argentina.]
Instead of denoting squares by xy and edges by {hxy, vxy}, it’s convenient to
use “even/odd coordinates” instead (see exercise 145). In that system, a pair of odd
numbers (2x+1)(2y+1) denotes a square, and the edge between two adjacent squares
is represented by the midpoint between them. For example, the 24 • 81 options sketched
above would then take the form
‘11 aaaa 01:a 12:a 21:a 10:a’, . . . , ‘b7 ccba a7:a b8:c c7:c b6:b’.
Such coordinates are easier to work with under reflection and rotation.
134. (O, P, Q, . . . , Z) occur respectively (0, 1672, 22, 729, 402, 61, 36, 48, 174, 259, 242,
0) times, sometimes twice in the same solution; one solution features four pentominoes.
[Kate Jones introduced such questions in the Multimatch1® I user manual (1991).]
135. Indeed, the total number of solutions is enormous; Monte Carlo estimates predict
~ 9 x 108 of them for any fixed placements of aaaa, bbbb, cccc that aren’t obviously
impossible. Therefore it’s natural to impose extra conditions. The elegant wrapping
below permutes colors cyclically and has solid colors on every edge of the cube! Inves
tigations by H. L. Nelson, F. Fink, and M. Risueno showed that 61 such solutions are
possible; see W. E. Philpott, JRM 7 (1974), 266-275. See answer 145 for an even/odd
July 26, 2019
7.2.2.1 answers to exercises 155
coordinate system that is useful for representing this problem internally. polyhedron
Uri
triacontahedron
rhombuses
stellated
dodecahedron
isosceles triangles
icosahedron
coordinates
golden ф
automorphisms+
Boothroyd
(Wrapping the surface of a symmetrical polyhedron is a nice way to avoid awk quintominal dodecahedra
ward boundary conditions when arranging MacMahon-like tiles. Dario Uri devised
39 such problems in 1993, together with ingenious mechanical frames for building
the results. Here, for example, is a rhombic triacontahedron (30
rhombuses) and a stellated dodecahedron (60 isosceles triangles),
based on all possible ways to put distinct colors from {red, green,
blue, yellow, black} on the edges. His report “Tessere di Mac
Mahon su superfici tridimensionali” is online at www.uriland.it .)
136. The main challenge is to find a good way to represent the faces and edges of a
dodecahedron. Perhaps the nicest is to represent the faces by vertices of an icosahedron,
with the three-dimensional coordinates (0, (—1)ьф, (—1)c)aa, where (x,y,z)a = (z, x, y);
let abc stand for this face, for 0 < a < 3 and 0 < b, c < 2. A face is adjacent to its five
nearest neighbors; we can represent the edge between abc and a b'c as the midpoint
(abc + a b'c )/2. These 30 midpoints have two forms, either ab = (0, (—1)bф, 0)aa or
abcd = 2((-1)b, (-1)cФ, (—1)dФ2)^a. The corresponding XCC problem can now be
formulated as usual, with 120 options for each face. For example, a typical option for
face 201 is ‘201 01243 20:3 1100:0 2001:1 2101:2 1110:4’.
We can force the first tile to be in a particular place by default. Algorithm C
needs only 9 megamems to solve the resulting problem, and produces 60 solutions.
Of course many of those solutions are equivalent. There are 120 transformations
that preserve the dodecahedron and icosahedron as represented above, generated by
three reflection matrices and two orthogonal matrices,
-1 0 0 +1 0 0 +1 0 0
D0 = 0 +1 0 , D1 = 0 -1 0 , D2= 0 +1 0 ,
0 0 +1 0 0 +1 0 0 -1
/ 0 0 1\ 1 / -1 -ф 1/ф \
P= 1 0 0 , Q= -ф 1/ф -1 .
0 1 0 2 1/ф -1 -ф
Applying any combination of these, and remapping the colors to agree with the de
fault placement, gives an equivalent solution. It turns out, as Conway discovered by
hand(!), that there are just three inequivalent solutions, having respectively 4, 6, and
12 automorphisms (hence occurring 30, 20, and 10 times in the output of Algorithm C):
137. (a) This is an easy application of Algorithm C, with 14 + 12 items and 7 • (1 + random trials
6 x 6) = 259 options. (Clever reasoning also allows it to be established by hand, with Historical notes
Bradley
a search tree of size 15.) Super Dom
(b) No. Again Algorithm C gives the answer quickly. Hydes
Patent
(c) Thousands of random trials indicate that about 93% of the 1270 choices have Whitehouse
no solution; about 5% have just one solution; about 1% have two solutions; and the Haswell
remaining 1% have three or more. flipping
remapping
(d) About 0.4% of all cases work, as in the example shown. reflection
Historical notes: Milton Bradley Company introduced Drive Ya automorphisms
automorphisms
Nuts in 1970; the name of its inventor has unfortunately been 90° rotation
forgotten. It was preceded by a much more difficult puzzle with checkerboard
19 hexagons in three concentric rings, called Super Dom [H. Hydes, British Patent Super Heads & Tails
Swift
149473 (19 August 1920)], and by several similar puzzles [H. Hydes and F. R. B.
Whitehouse, British Patent 173588 (29 December 1921); G. H. Haswell, U.S. Patent
1558165 (20 October 1925)], featuring both kinds of edge-matching rules.
138. (a) We can name the tiles ABcd, ABdc, ACbd, . . . , DCba. Assuming that ABcd is
in the top left corner, a straightforward application of Algorithm C (with 2118 options
involving 48 + 48 items) will output 42680 solutions, in 13 gigamems. As in other such
problems, however, these outputs include many that are essentially the same. Up to
96 equivalent solutions are related by the operations of shifting any cell to the top
left position and/or flipping horizontally and/or flipping vertically, then remapping the
colors. For instance, the given example has six automorphisms: We can shift it two
columns right, then map A ^ C ^ D ^ A, a ^ c ^ d ^ a; we can also shift two rows
down, reflect left-right, then A о D and a о d. Hence it contributes 96/6 = 12 cases
to the total of 42680. Altogether there are (79, 531, 5, 351, 6, 68, 12, 4) cases with
respectively (1, 2, 3, 4, 6, 8, 12, 24) automorphisms, hence 79 + 531 + 5 + 351 + 6 + 68+
12+ 4 = 1056 essentially different solutions. One with 24 symmetries is shown below (it
leads to itself if we move right 1 and down 2, and/or reflect horizontally or vertically).
(b) Now Algorithm C, given 1089 options involving 49+60 items, quickly finds just
six solutions — three different pairs related by transposition, each of which is symmetric
under 90° rotation, all with heads and tails in the same places.
(c) Take any of the three solutions to (b), reflect it top-down, interchange heads
with tails, and swap B о D, b о d. For example, the dual of the given solution
is shown below. Alternating all-heads with all-tails, in checkerboard fashion, yields
uncountably many tilings of the plane.
[These tiles are believed to have originated in 1990 with a puzzle called “Super
Heads & Tails,” designed by Howard Swift and produced in a limited edition.]
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 157
139. (a) Say that two sets of nine are essentially the same if one can be obtained reflecting
from the other by remapping the colors, and/or reflecting all of the pieces, and/or flipping
Haubrich
interchanging heads with tails. For example, 4! x 2 x 2 = 96 different choices of nine historical note
are equivalent to the set
® 13, SI E3 S- S- S- S3 ЕЖ w
In each case we can flip the pieces and/or swap heads о tails, then remap the colors
to get the original tiles.
[This problem was first solved by Jacques Haubrich in 1996, who considered color
remapping only (hence he had 54498 equivalence classes). Haubrich has collected 435
inequivalent puzzles, from around the world, that consist of nine tiles with two heads
opposite two tails. But only 17 of them have all tiles different and all four objects
different on each tile; for example, at least one tile such as ABcb is usually present. The
first “pure” HHtt puzzle in his collection was made by the Hoek Loos company in 1974.]
140. (a) We save a factor of 4! by applying exercise 122 with v = a. Then Algorithm C
gives respectively (10, 5, 6) solutions. The true numbers, however, are (5, 3, 3), be
cause the shapes are symmetrical — and because the middle solution has an additional
symmetry: It goes into itself if we rotate by 180° and permute the colors.
(b) The scaled-up versions of are impossible. But we have
with respectively (4, 4, 3) solutions; and there are unique solutions to the other five:
(c) These shapes, with respectively (7, 9, 48, 2, 23, 28, 18) solutions, are a bit eas central symmetry
ier to handle. The “wave” has six solutions with central symmetry; the “bar” has four. Trioker
Odier
Patent
Roussel
Multimatch®
Gottfried
Nitty Gritty
Skor-Mor Corporation
Langford
cylinder
reflections
restricted growth strings
set partition
historical note
[Vertex-colored triangles have been named ‘Trioker’ by Marc Odier; see French Thurston
Patent 1582023 (1968), U.S. Patent 3608906 (1971), and the book Surprenant Triangles, cylindrical
toroidal
which he published with Yves Roussel in 1976. They also are sold as Multimatch1® IV.]
Kadon Enterprises
141. (a) Using exercise 122 with v = a yields respectively (138248, 49336, 147708) solu Doris'®
tions in (1390, 330, 720) gigamems. Then we divide by (8, 4, 4) to remove symmetries of
the board, getting (17281, 12334, 36927) solutions that are essentially distinct. [These
numbers were first computed by Toby Gottfried in (1998, 1999, 2002). He had been
interested in the puzzle ever since seeing the 5 x 5 version that was sold by Skor-Mor in
1970 under the name “Nitty Gritty.” The puzzle is extremely difficult to solve by hand,
in spite of the many solutions; Langford himself was unable to solve the 3 x 8 case.]
The 12334 solutions for 4 x 6 include 180 that have matching colors at the left
and right. Each of these patterns therefore tiles a “cylinder”; and the 180 form 30
families of 6 that are equivalent to each other by rotating the cylinder. Similarly, 1536
of the 36927 solutions for 3 x 8 are cylindrical, making 192 families of 8. The example
illustrated is one of 42 that have the same solid color at both left and right.
(b) Any solution can be used to tile the plane in combination with its mirror
reflections and its 180° rotation (which is a reflection of a reflection).
The 17281 solutions include 209 for which the hole is surrounded by a single color.
Six of these have matching colors at two opposite sides; the one illustrated will tile the
plane in conjunction with its mate, which is obtained by swapping b о c.
The 4 x 6 example illustrated is the unique solution for which both pairs of
opposite sides induce exactly the same color partition (the restricted growth strings
0121120 and 01220). Thus it too will tile the plane together with its b о c mate.
[Vertex-matched squares, with incomplete sets of tiles, first appeared in puzzles
devised by E. L. Thurston, U.S. Patents 487797 (1892), 490689 (1893).]
142. Each boundary between the square cells containing octagons now has two sec
ondary items that receive color. For example, a typical option for Algorithm C is now
‘10 aabc a10:a r10:a l11:b a11:b b21:c l21:c r20:a b20:a’, where axy, bxy, lxy, and rxy
denote the half edges above, below, left, and right of (x, y). The number of solutions,
again using exercise 122 with v = a, is 2 • (132046861,1658603, 119599) in cases (i),
(ii), (iii), found in (2607, 10223, 77) gigamems. Case (i) includes 2 • (193920,10512, 96)
“cylindrical” arrangements in which the colors match at top/bottom, left/right, both;
one of the 96 “toroidal” examples is shown. Case (ii) includes 2 • 5980 cylindrical
arrangements that match at left/right. Case (iii) has no cylindrical examples.
[Many other possibilities arise, because neighboring octagons can match without
lying in a square grid. Kadon Enterprises offers attractive sets called ‘Doris'® ’.]
143. (a) simplex (8, 6, 8, 2, 0, 0, 0); simplex (7, 4, 7, 3, 0, 0, 0); simplex (5, 5, 5, 4, 0, 0, 0).
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 159
(b, c) Nonnegative integers x0x1x2x3x4x5 define such a polygon if and only the canonical form
boundary path returns to its starting point, which means that x0 + x1 = x3 + x4 and OEIS
Boddington
x1 + x2 = x4 + x5. Rotating by 60° replaces x0x1x2x3x4x5 by x5x0x1x2x3x4; reflecting even/odd coordinate system
left о right replaces x0x1x2x3x4x5 by x0x5x4x3x2x1. Hence we get a canonical form odd coordinates
chiral
by insisting that x0 > x3 > x5 > x1: Every sequence of nonnegative integers (a, b, c, d)
with a > b > c > d defines the boundary x0x1x2x3x4x5 of a unique convex triangular
polygon, where x0 = a, x1 = d, x2 = a - b + c, x3 = b, x4 = a - b + d, x5 = c.
Furthermore, that polygon contains exactly N = (a + c + d)2 - b2 - c2 - d2 triangles.
Given N, the following algorithm visits all relevant (a, b, c, d). For c = 0, 1, . . . ,
while 2c2 < N do the following: For d = 0, 1, ... , while d < c and 2c(c + 2d) < N, let
x = N + c2 + d2. If x mod 4 = 2, for every divisor q of x such that q = x (modulo 2) and
q2 < x, set a ^ (x/q+q)/2 —c—d and b ^ (x/q—q)/2. Visit (a, b, c, d) if a > b and b > c.
When N = 24 this algorithm visits six (a, b, c, d), namely (7, 5, 0, 0), (5, 1, 0, 0),
(5, 1, 1, 0), (6, 6, 2, 0), (2, 2, 2, 2), (4, 4, 3, 0). The second, fourth, and sixth are the shapes
of exercise 140. The other three cannot be tiled properly with Langford’s 24 tiles.
[See OEIS sequence A096004, contributed by P. Boddington in 2004.]
(d) Yes. One way is simplex (a + c + d, a + c, a + d, a - b + c + d, 0, 0, 0).
144. The constraints are severe, because a solid color is needed at transitions between
regimes. Algorithm C (with v = a as in answer 142) quickly finds 2^102 solutions to (ii).
But surprisingly many arrangements arise in case (i); Algorithm C finds 2 • 37586004
of them, not so quickly (643 teramems)!
(These tiles suggest many intriguing questions. For example, suppose we restrict
consideration to making a big hexagon from 24 small ones. There are 224 ways to specify
whether each position should be matched at vertices or edges; but very few of those
specifications are actually realizable. Can the realizable ones be nicely characterized?)
145. Suppose 0 < i < l, 0 < j < m, and 0 < k < n. Let (2i, 2j, 2k) represent vertex
(i, j, k); let (u + v)/2 represent the edge between adjacent vertices u and v; let (a + b)/2
represent the face containing parallel edges a and b; let (e + f)/2 represent the cell
containing parallel faces e and f. Thus, the triple (x, y, z) represents a vertex, edge,
face, or cell when it has respectively 0, 1, 2, or 3 three odd coordinates.
For example, (2i, 2j+1, 2k) represents the edge between vertices (i, j, k) and
(i, j+1, k); (2i+1, 2j, 2k+1) represents the face whose vertices are (i, j, k), (i+1, j, k),
(i, j, k+1), (i+1, j, k+1); and (2i+1, 2j+1, 2k+1) represents the cell whose eight vertices
are (i + (0 or 1), j + (0 or 1), k + (0 or 1)).
Notice that (a + b)/2 represents the vertex between adjacent parallel edges a
and b; (e + f)/2 represents the edge between adjacent parallel faces e and f; (p + q)/2
represents the face between adjacent cells p and q.
(We can use a similar convention in two dimensions, as an alternative to the ‘H’
and ‘V’ items in situations like answer 109.)
146. (a) Each color occurs four times on the “visible” faces and at most twice on the
“hidden” faces. So the five adjacencies account for all six occurrences of five colors.
(b) For every partition of {a, b, c, d, e, f} into three pairs {u,u7}, {v,v7}, {w,w7},
there are two chiral cubes having u opposite u', v opposite v', w opposite w'. Order
the colors so that u < u', u < v, v < v', v < w, v < w'; there are 30 ways to do this.
The cube named uu'vv'ww' is the one that can be placed with u on top, u' on the
bottom, v in front, v' in the back, w at left, w' at the right. For example, the cubes
in (*) are named aebfcd, acbfde, acbdef, afbdec, abcedf, aebcfd.
July 26, 2019
160 ANSWERS TO EXERCISES 7.2.2.1
(c) We can set this up for Algorithm C by specifying 6 • 30 • 24 options, one for automorphisms
each cube position, cube name, and cube placement. There are 6 primary items for the essentially different
exact cover problem
positions; 30 secondary items for the names; 4 • 6 primary items uc , dc , fc , bc for colors Gardner
on the top, bottom, front, and back, where c G {a, b, c, d, e, f}; and 6 secondary items Perjes
even/odd coordinates
hk for the colors hidden between positions k and k + 1. For example, the leftmost cube array, 3-dimensional
in (*) corresponds to the option ‘1 aebfcd ua de fb bf h0:c h1:d’. tensor
If we eliminate all but one option for position 1 (thus saving a factor of 720),
there are 2176 solutions. Each solution is, however, potentially equivalent to 95 others,
because there are 16 possible rotations/reflections together with 6 cyclic permutations
(followed by remapping the colors of the leftmost cube). For example, the solution
illustrated has 12 such automorphisms. Further study shows that only 33 solutions are
“essentially different” — of which (17, 9, 3, 1, 3) have (1, 2, 4, 6, 12) automorphisms.
(d) Yes, in lots and lots of ways. The 720 • 2176 solutions obtained without fixing
the leftmost cube involve 15500 different 6-tuples of cubes; and the exact cover problem
for which those 6-tuples are the options has 163,088,368 solutions.
[This problem was posed by Martin Gardner in Scientific American 204, 3 (March
1961), 168-174 (long before the “Instant Insanity” craze), and he extended it to
question (c) in Scientific American 235, 3 (September 1978), 26. A solution to (d)
that involves five symmetrical arrangements was found by Zoltan Perjes in 1981; see
Gardner’s book Fractal Music, Hypercards, and More (1992), 97.]
147. (a) The “even/odd coordinates” of exercise 145 are ideal for representing the cube
positions and the faces between them. For example, the colors in the 1 x 2 x 2 brick
that was illustrated with the exercise are nicely represented by the 3 x 5 x 5 array
.d.d.
a.a c.e.c .b .b.
.f.f.
a.a c.d.c .b .b.
.e.e.
107:c 109:c 301:c 303:c 305:c 307:c 309:c’. The number of solutions is reduced by a automorphisms
factor of 720 if we remove all but one of the 720 options for position 111. MacMahon
Jocelyn
It turns out that the brick’s face colors have an interesting property in every historical notes
solution: A repeated face color occurs only on opposite, parallel faces. The example Patent
Mayblox
1 х 2 х 2 brick has face colors ab x cc x de; the 2 x 3x 5 brick in (a) has colors aax bb x cc. Kowalewski
A brick is considered to be essentially the same as any other that’s obtained Winter
MacMahon
from it by rotation, reflection, and/or permutation of colors. The example 1 x 2 x 2
brick above has 8 automorphisms; for example, we can reflect top о bottom and swap
d о e. The 2 x 3 x 5 brick above has 2 automorphisms: The nontrivial one reflects
front о back, top о bottom, e о f.
There’s another 1 x 2 x 2 brick, whose face colors are ab x cd x ef. It has 16 auto
morphisms. Thus it occurs only once among the three solutions found by Algorithm C
when (l, m, n) = (1, 2, 2); the other two solutions are equivalent to each other.
There’s a unique 1 x 2 x 3 brick, easily found by hand. It has colors ab x cc x dd,
and 8 automorphisms. (Clearly 1 x m x n is possible only if mn < 6.)
The 2 x 2 x 2 bricks are especially interesting because MacMahon himself and his
friend J. R. J. Jocelyn considered this case (with six different face colors), when they
introduced the 30 6-color cubes in U.K. Patent 8275 of 1892. They observed that one
can choose any “prototype” cube and replicate it at twice the size, by assembling eight
of the other cubes. This can be done in two ways — using, in fact, the same eight cubes.
But those two solutions are isomorphic, in 24 different ways. [See Proc. London Math.
Soc. 24 (1893), 145-155. Their 8-cube puzzle was sold under the name “Mayblox.”]
Gerhard Kowalewski, in Alte und neue mathematische Spiele (1930), 14-19, found
a 2 x 2 x 2 brick with face colors aa x bb x cd. Ferdinand Winter, in Mac Mahons
Problem: Das Spiel der 30 bunten Wiirfe.l (1933), 67-87, found another, with face colors
aa x bc x de. And there’s also a fourth solution, having Winter’s face colors:
MacMahon Kowalewski
.c.c. .. d.
d. . . .c.c. b..
.. b.. .b.b. .. c.
d. . . .b.b.
.a.a. e.b.f e.a.f .a.a. c.e.d c.f.d .a.a.
.f.e. .f.e.
; .f.f. .e.e.
.a.a. e.b.f .c.c. e.a.f .b.b. .a.a. c.e.d .d.c. c.f.d .a.a.
.d.d. .d.d. .b.b. .b.b.
Winter Fourth
.b.b. f. .
.. f.. .b.b. .b.b. .b.b.
.a.a. d.c.e d.c.e .a.a. .a.a. d.f.e .c.c. d.f.e .a.a.
.e.d. .e.d.
; .e.d. .e.d.
.a.a. d.f.e .b.b. d.f.e .a.a. .a.a. d.f.e .b.b. d.f.e .a.a.
.c.c. .c.c. .c.c. .c.c.
(6, 8, 1, 0); aa X bc X de, (0, 6, 0, 0); ab X cc X dd, (0, 4, 2, 0); ab X cc X de, (0, 2, 0, 0); barycentric coordinates
ab X cd X ee, (0, 2, 0, 0); ab X cd X ef, (0, 7, 0, 0). Case 2 X 3 X 5: aa X bb X cc, (0, 2, 0, 0). McComb
Scherp huis
(Conspicuous by its absence is the case l = m = n = 3. There’s no 3 X 3 X 3
brick, although we can come close: A 3 X 3 X 3 without a corner can be made from 26
of the 30; or without the middle cube and the one above it, from 25.)
148. There are eleven such cubes, and they can be matched in many pleasant ways:
aaaaaaba
aababcba
a / l> a^f-b a^K-b a^K-b a^K-b a^f-b a^f-b a^f-c
bccccbcc
bbbccccc
.a.a.a.
.a .b .a. a.b.a.c .b. c .b.
.a. .c.b.c. .b.
c a.c .b .a .b. a.b.a.c .c. b .c. b.c c
.c. .b.a.a. .c.
.a .b .a. a.c.b.c .b. c .b.
.c.c.c.
149. Label the vertices with nonnegative barycentric coordinates wxyz, where w +
x + y + z = 3. Also label the ten unit tetrahedra with barycentric coordinates stuv,
where s + t + u + v = 2; the vertices wxyz of tetrahedron stuv are then stuv +
{1000, 0100, 0010, 0001}. Introduce ten primary items stuv for the tetrahedra, and ten
more abcd, abdc, abce, adec, . . . , bcde, bced for the different colorings. And introduce
20 secondary items wxyz for the vertices.
Then the admissible vertex colors are the solutions to the XCC problem with 1200
options ‘stuv a v1:p1 ... v4:p4’, where a is a coloring, v1v2v3v4 are the vertices of stuv,
and p1p2p3p4 is an even permutation of a’s colors. Curiously, this problem has 2880
solutions (found in 500 M^)— and they’re all equivalent to the one below, under the
5! 4! = 2880 automorphisms present.
(This problem was posed in 2015 by J. McComb, and solved by J. Scherp huis.)
150. Notice that there are fourteen distinct pieces, with four pairs of two. So we use
Algorithm M, with 14 primary items for pieces and 64 for cells. We also introduce
secondary items for edges between cells, with colors to indicate the presence or absence
of links. The final two pieces must obviously be adjacent, hence we can combine them
into a “super-piece” of size 11; then all interfaces between adjacent cells are identical.
We can remove symmetry by forcing the super-piece to be in one of 18 positions.
July 26, 2019
7.2.2.1 answers to exercises 163
Hoffmann
Reason, Henry, Manufacturing Company
factoring
multiplicities
Pegg
Phillips
author
crossings
avoids most of the lower left quadrant, and solution (iv) avoids the entire right column.
If we ignore blank spaces, the links form eight different paths, all of length 34. Paths
(i), (ii), (iii), (iv) occur in respectively 1, 15, 9, 3 of the 43 solutions. [The Endless
Chain Puzzle was distributed circa 1887 by Reason Manufacturing Company.]
151. (a) The key idea is to start by factoring this problem, by considering only the
task of edge-matching between adjacent dominoes, while ignoring the loop details.
Algorithm M applies, with primary items 1-9 and a-i for the distinct on-off pat
terns of attachment points, as well as primary items ij for each cell to be covered (0 <
i < 8,0 < j < 9), and two special primary items H, V. There are 63+64 secondary items
hij and vij , to indicate path/nopath at internal attachment points. Typical options:
152. This (factored) problem is like the previous one, but with an additional pattern j
of multiplicity 11, and without H or V. One needs to be lucky to find a solution; the
author struck it rich with Algorithm M after 35.1 T^.
[Notice that exactly 32 of the 48 path dominoes have no crossings. Thus it is
irresistible to try to place them on a chessboard, so as to form a single noncrossing
July 26, 2019
164 ANSWERS TO EXERCISES 7.2.2.1
loop. Unfortunately, Algorithm M tells us that such a mission is impossible, even with monomino
multiple loops, because the corresponding factored problem has no solution. Something multiplicity
Line puzzles
interesting, however, can surely be done with those 32.] Darrah
Binary Arts
153. (a) Algorithm M quickly verifies the uniqueness of the solution below, if we add random choices
a blank monomino of multiplicity 4. [“Line puzzles” like this were invented by Bill author
Darrah; several of his ingenious designs were made by Binary Arts in 1994 and 1999.] Wainwright
Friedman
(b) There are 30 patterns, three for each distinct choice of three connection points. Reid
(c) Trials with random choices of respectively (2, 2, 4) symmetry
sets of (2, 3, 4) distinct connection points usually give no dancing links, sometimes slow
Cutler
solutions at all. But one of the author’s first 1000 trials was Wainwright
suitable, and it led to a nice puzzle whose solution is shown. Jepsen
Ahearn
154. The integer solutions to P (n) = n(n + 1)2 (n+ 2)/12 = m2 involve perfect squares
u2 and v2 with v2 ~ 3u2. If |v2 — 3u2| is sufficiently small, v/u must be a convergent
to the continued fraction -\/3 = 1 + //1, 2,1, 2,1, 2,1, 2,... // (see exercise 4.5.3-42).
Pursuing this idea, let 0 = 2 + V3, <9 = 2 — V3, (an) = ((0n + 0n)/2) =
(1, 2, 7, 26, 97,...) and {bn) = <(0n — 0n)/(2V3)> = (0,1, 4,15, 56,...). Notice that
a2n = 3b2n + 1; (an + 3bn )2 = 3(an + bn)2 — 2. We find that P (n) is a perfect square if
and only if n = 6b2m for some m (thus n = 0, 6, 96, 1350, 18816, . . . ) or n = (am +3bm)2
for some m (thus n = 1, 25, 361, 5041, 70225, . . . ).
[See R. Wainwright, in Puzzlers’ Tribute (A. K. Peters, 2002), 277-281; also Erich
Friedman’s survey in www2.stetson.edu/~efriedma/mathmagic/0607.html.]
155. (a) Algorithm M finds 8 • 7571 solutions, in 60 G^.
(b) The maximum is 35 (not easy to find!), and the
minimum is 5. [This exercise was suggested by Robert Reid,
who found a minimum solution by hand in 2000.]
156. At level l of backtracking, branch on all ways to fill the leftmost unfilled cell of
the topmost unfilled row. Even though no MRV heuristic is used, this method needs
just 2.0 teramems (and negligible memory) to find 18656 solutions. The search tree
has 61636037366 nodes.
We can save a factor of 8 by removing symmetry: The 1 x 1 square can be
confined to cells (i, j) with i < 18 and j > 35 —i. Furthermore, if (i, j) is on the diagonal
(j = 35 — i), the context of the 1 x 1 square must be either or -b|-, and we can insist on
the former. Now we find 2332 solutions (and 6975499717 nodes), in just 235 gigamems.
By contrast, the MCC problem (61) for n = 8 has 1304 items and 7367 options
of total length 205753, when we restrict the options of #1 to i < 18 and j > 35 — i.
It needs 490.6 teramems to find 2566 solutions; postprocessing reduces that number to
2332, because 468 of those 2566 have #1 in position (i, j) with j = 35 — i.
We conclude that a dancing-links approach is decidedly not the method of choice
for this partridge problem; straightforward backtracking with bitwise operations is more
than 2000 times faster! Indeed, we might consider ourselves fortunate to pay “only” a
2000-fold cost penalty, since each of the 841 options for #8 in (61) contributes 65 nodes
to doubly linked lists. Such updating and downdating keeps the dancers extremely busy.
[Historical notes: The 2332 solutions for n = 8 were first found by Bill Cutler
in 1996, using a refinement of the backtrack approach described above. At that time
no solutions for n < 11 had been known, although Wainwright knew how to solve
12 < n < 15 in 1981, and C. H. Jepsen and S. Ahearn had presented constructions for
11 < n < 33 in Crux Mathematicorum 19 (1993), 189-191. The puzzle can surely be
solved for all n > 7, but no proof is yet known.]
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 165
157. Algorithm M readily shows the nonexistence of perfect packings, but the back quadrants
track method of exercise 156 is much better to show that we can’t pack all but one octants
dominating sets
2 х 2. That method also shows that we can pack all but two of them: queen graph
kernels
maximal independent sets, see kernels
3 6 6 6
3
____ 1
4 6 6 5
4 u
5
4
6 5 5 5
158. The following solutions can be proved optimum with bitwise backtracking as in
exercise 156:
159. Replace # by four primary items #0, #1 , #2, #3 representing “quadrants,” and
use #2Li/4J + Lj/4J in place of # in (64). Then partition into ten separate cases, in which
the multiplicities m0m1m2m3 of #0#1#2#3 are respectively (2012, 2111, 2120, 3002,
3011, 3020, 3110, 4010, 4001, 5000). (Omit options containing #k of multiplicity 0.)
These cases produce (134, 884, 33, 23, 34, 1, 16, 0, 22, 0) solutions, in (95, 348, 60, 23,
75, 8, 19, 2, 10, 0) megamems. (Notice that 4 • 134 + 4 • 884 + 8 • 33 + 4 • 23 + 8 • 34 + 8 •
1 + 4 • 16 + 8 • 0 + 4 • 22 + 4 • 0 = 4860.) The running time has decreased by a factor of 20.
[For larger values of n we could divide the cells into nine regions: eight octants,
plus a special region containing the diagonals (and the middle row, column if n is odd).]
160. There are 589 components, among which are 388 isolated vertices and one giant
of size 3804. The other 200 components have sizes ranging from 2 to 12. (For example,
the first three solutions in (65) belong to the giant component; the other belongs to a
component of size 8.)
161. In general, consider the problem of finding all the m-vertex dominating sets of a
graph G; the n х n m-queen problem is the special case where G is the queen graph of
order n. Then the options (64) have the form ‘# v v1 . . . vt’, where {v1 , . . . , vt} are
the vertices adjacent to v, and # is a special primary item of multiplicity m.
Variant (i) is equivalent to asking for all kernels of size m (all of the maximal
independent sets). Let there be a secondary item e for every edge in G; the options
are then ‘# v v1 . . . vt e1 . . . et’, where ej is the edge between v and vj. An 8 х 8
chessboard has 8 • 91 = 728 kernels of size 5. (It also has 6912, 2456, and 92 kernels of
sizes 6, 7, and 8; see exercise 7.1.4-241(a).)
For variant (ii) we simply shorten v’s option to ‘# v1 . . . vt’; some other option
must then cover v. Exactly 352 of the 5-queen solutions satisfy (ii).
Variant (iii) seems a bit harder to formulate. Let there be a secondary item v for
each vertex v. The option for choosing v can then be ‘# v v:1 v1 ... vt v1:0 ... us :0’,
where {u1, . . . , us } = V \ {v, v1, . . . , vt} is the set of vertices not adjacent to v. The
8 х 8 chessboard has 20 clique-dominators of size 5.
July 26, 2019
166 ANSWERS TO EXERCISES 7.2.2.1
163. Sometimes Algorithm M is called on to choose zero or more items from an empty
list. Then it sets FT[l] ^ i and xl ^ i, where i is the item whose list is empty; but
step M5 doesn’t actually tweak anything. The peculiar rule in (71) ensures that step M8
doesn’t actually untweak anything as we backtrack.
164. If xj < N, node xj is the header for item xj ; there’s no further option for such j.
[A good implementation will also extend answer 12, so that the relative positions
of each xj in the search tree are identified. For this purpose one can add a new array
SCORE, setting SCORE[l] ^ 9i and FT[l] ^ 0 at the end of step M3. When printing the
jth step xj of a solution, the old answer 12 is used if ft[j] = 0; otherwise that answer is
modified as follows: If x < N and (x = FT[j] or x = TOP(FT[j])), print ‘null NAME(x)’;
otherwise print option x as before. Conclude by looping with i ^ 0, q ^ FT[j] rather
than i ^ TOP(x), q ^ DLINK(i); report ‘k of SCORE[j] ’ rather than ‘k of LEN(i) ’.]
165. (a) To cover 2 of 4, we have 3 choices at the root, then 3 or 2 or 1 at the next
level, hence (1, 3, 6) cases at levels (0, 1, 2). To cover 5 of 7, there are (1, 3, 6, 10,
15, 21) cases at levels (0, 1, . . . , 5). Thus the search profile with item 1 first is (1, 3, 6,
6 • 3, 6 • 6,6 • 10, 6 • 15, 6 • 21). The other way is better: (1, 3, 6, 10, 15, 21, 21 • 3, 21 • 6).
(b) With item 1 first the profile is (a0, a1, ... , ap, apa1, ... , apaq), where aj =
j+dd . We should branch on item 2 first because ap+1 < apa1 , ap+2 < apa2 , . . . , aq <
apaq-p, aqa1 < apaq-p+1 , . . . , aq ap-1 < apaq-1. (These inequalities follow because
the sequence {aj) is strongly log-concave: It satisfies the condition aj > aj-1aj+1 for
all j > 1. See exercise MPR-125.)
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 167
166. (a) The “monus” operation x -. y = max(x - y, 0) is good for situations like this: monus
author
9p = (LEN(p) + 1) - (BOUND(p) - SLACK(p)). multiplicity
MCC problem
automorphisms
(b) It’s better to branch on p' (although this may be counterintuitive). symmetry can be broken
[The author’s implementation of step M3 breaks ties by first preferring an item
with smaller slack, then preferring longer len when the slacks are equal. Thus, his
MRV replaces answer 9 by this: Set 9 ^ to, p ^ RLINK(0). While p = 0, do the
following: Set A ^ 9p; if A < 9 or (A = 9 and SLACK(p) < SLACK(i)) or (A = 9 and
SLACK(p) = SLACK(i) and LEN(p) > LEN(i)) set 9 ^ A, i ^ p; then set p ^ RLINK(p).
167. Step M3 isn’t precisely defined; therefore any change to vp could possibly affect
the behavior. But let’s assume that step M3 is implemented as in exercise 166.
Even so, there can be differences. A minor difference arises, for instance, if there
are no options: A primary item with multiplicity [0 . . 1] will be inactivated by covering
in step M4; with multiplicity [0 . . 2], it will become inactive at the end of step M5.
There can also be more significant differences. Suppose there’s just one option,
‘a’, and one primary item. If a has multiplicity 1, we simply cover a as in Algorithm X.
But if a has multiplicity [1 . . 2], we’ll do some tweaking and untweaking — even entering
a new level, and taking a null branch there.
On the other hand, the differences can’t get much worse. Let bound0 (p) and
bound1 (p) denote the values of bound(p) when the upper bound vp has respectively
been specified as Mp and Mp I A. If the same options are chosen, we’ll have BOUND 1 (p) =
BOUNDo(p) + S throughout the algorithm, because BOUND(p) is adjusted appropriately
whenever the algorithm recursively reduces the problem by removing an option. Also
slack1 (p) = slack0(p) + S. One can then prove, by induction on the computation,
that the same options are indeed chosen (possibly with different amounts of tweaking).
Any two values of vp that are Mp + 2 or more will be totally equivalent.
168. Introduce a new primary item ‘!’ and a new secondary item ‘+’. Replace the two
copies of a by ‘! +:0’, ‘! a’, ‘a +:1’. [Similarly, three copies of a can be replaced by
‘! +:0’, ‘! a’, ‘!! ++:0’, ‘!! a +:1’, ‘a ++:1’, after introducing ‘!!’ and ‘++’.]
169. Let there be one primary item, #, together with one secondary item for each
vertex. And let there be one option, ‘# v v1 :0 . . . vd:0’ for each vertex v, where v1
through vd are the neighbors of v. Finally, let # have multiplicity t. [Notice that the
secondary items in this construction are colored either with 0 or not at all!]
170. Introduce the primary item !v for each vertex, and give it d + 1 options: ‘# !v
v:1 v1:0 . . . vd:0’, ‘!v v:0 v1:1’, ‘!v v:0 v1:0 v2:1’, . . . , ‘!v v:0 v1:0 . . . vd-1 :0 vd:1’.
171. Let there be ten primary items v, for 0 < v < 10; also fifteen primary items #uv,
with multiplicity [1 . . 5], for each edge u --- v, where the edges are 0 --- 1 --- 2 --- 3 --
4 --- 0, 0 --- 5, 1 --- 6, 2 --- 7, 3 --- 8, 4 --- 9, and 5 --- 7 --- 9 --- 6 --- 8 --- 5. Let there
be 26 • 10 secondary items av through zv, for 0 < v < 10; also 26 • 30 secondary items
auv through zuv , for u --/- v; also a secondary item w for each word in, say, WORDS(1000).
There are 26 options, ‘#uv au av ’ through ‘#uv zu zv ’, for each edge. And there are
10 options for each word; for example, the options for added are ‘v av :1 bv :0 cv :0 dv :1
ev :1 fv :0 . . . zv :0 a02 a03 a06 a07 a08 a09 d02 . . . e09 added’, where 0 < v < 10.
Every solution to this MCC problem will be obtained 120 times, because the
Petersen graph has 120 automorphisms. But symmetry can be broken by choosing the
labels of 0, 1, and 3 at levels 0, 1, and 2, and by ordering the label ranks so that r0 > r1,
r0 > r2, r0 > r3, r0 > r6, r1 > r4, r1 > r5 , r3 > r7, r3 > r8 , r3 > r9 .
July 26, 2019
168 ANSWERS TO EXERCISES 7.2.2.1
There are two solutions in WORDS(834), namely muddy, thumb, books, knock, ended, parity
apply, fifth, grass, civil, (refer or fewer), found in 3.5 T//. Aztec diamond
double counting+
172. A construction analogous to answer 170 generates all solutions to the weaker
problem where connectivity isn’t tested; it’s easy to remove the unconnected solutions
from Algorithm M’s output. Consider cycles first: There are 1 + d2 options for each
primary item !v, namely ‘!v v:0’ and ‘# !v v:1 v1:a1 . . . vd:ad’, where a1 . . . ad is a
binary vector with a1 + • • • + ad = 2. For the path problem, the options for the starting
vertex should have a1 + • • • + ad = 1, not 2. The options for all other vertices that
aren’t adjacent to the starting vertex should have d additional options ‘# E !v v:1 v1 :a1
... vd:ad ’, with a1+ • ^+ad = 1, where E is a new primary item signifying the end vertex.
(a) Paths of length l are obtained when the multiplicity of # is set to l + 1.
First let’s restrict consideration to paths that start in the corner cell (0, 0). Then
every essentially distinct path occurs twice — reflected about the diagonal. (i) There
are 16 distinct snake-in-the-box king paths of length 31 from a given corner, found
in 6 T^. One of them, illustrated below, also ends at a corner; hence it occurs four
times, not two — twice in each direction. These paths are optimum, because we can
divide the board into sixteen 2 x 2 subsquares, each of which can contain at most two
kings. (ii) A single run, with the multiplicity of # set to [32 . . 33], suffices to find the
13 distinct knight solutions of length 31 in 58 G//, simultaneously showing that length
32 is impossible. One of the most remarkable solutions is shown below. (iii) With
bishops we should first eliminate all squares of the wrong parity, because they cannot
be connected to the start. Then the 32 solutions of length 12 are found in just 13 M^.
(It’s not difficult to prove by hand that an nx n board has exactly 2n-3 bishop solutions
of length 2n - 4, when n is even.) (iv) Rook solutions are even easier to enumerate
by hand: There are (n - 1)!2 of them, because we always have n - k choices at steps
2k — 1 and 2k. (Algorithm M finds the 7!2 = 25401600 solutions in 625 G^, while
generating also 21488110 disconnected impostors.) However, (n - 2)!2 - (n - 2)! of
those solutions are counted twice, because they go from corner to corner and have no
symmetry. Hence there are 25401600 — 517680/2 = 25142760 distinct rook solutions of
length 14. (v) Finally, there are 134 distinct queen solutions of length 11 — found and
proved optimum in 17 G^, despite having 16788 options of total length 454380(!). The
unique solution that occupies opposite corners is shown here. (You may enjoy finding
another unique 11-step path, which begins slowly by moving just one diagonal step.)
(i) Five solutions with 32 kings are found (in 3.7 T^); but they all have 3-cycles and
are disconnected. (ii) Knights, however, yield a big surprise: There’s a unique path of
length 33, doubly counted! (Found in 43 G^.) (iii) Bishop paths can’t have length 12
unless they start or end in a corner. (iv) There are N = (n — 1)!2 — 2(n — 2)!2
solutions where the rook first moves down, and N where it first moves sideways. Of
these, 2Nc end at (n — 1, n — 2) and are double-counted by central symmetry, where
Nc = (2Ln/2J— 1 (|_n/2_| — 1)!)2; Nt = 2(n—2)! end at (1, 0) and are not double-counted by
transposition; Nt end at (n — 2, n — 1) and aren’t double-counted by dual transposition.
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 169
So there are 2N - Nc - (2(n - 2)!2 - Nt) = 47691936 equivalence classes when n = 8. symmetry
(v) Another nice surprise greets us, namely a unique queen path of length 12! central symmetry
180 symmetry
The next step is to consider paths that start in (0, 2) and don’t end in the 12 types 4-fold symmetry
of cells already considered. And so on, for seven more cases. Of course rook counting 180 rotation
Burnside’s lemma
gets hairier and hairier; we shall omit it. Unexpectedly, there’s also another maximum
Dawson
queen path(!). All of these computations are fast, except that the kings need 6.3 Tp. Verbeek
Torbijn
Kautz
4 hypercube
4 n-cube
4 coil-in-the-box, see snake-in-the-box cycle
4 Beluhov
4
4
(b) Cycles are similar, but symmetry now becomes even trickier. (i) The six
distinct 31-cycles of a king are asymmetric, so they each appear eight times when
reflected and/or rotated. (ii) But the four distinct 32-cycles of a knight include two
that are equivalent to their transpose, and one (shown below) with central symmetry.
(iii,v) A bishop has 36 distinct 12-cycles, and a queen has five 13-cycles, all asymmetric.
(iv) A rook, on the other hand, has oodles of 16-cycles, some of which (like the one
illustrated) even have 4-fold symmetry under both horizontal and vertical reflection.
Every rook snake-in-the-box 16-cycle can be represented uniquely as (p0 q0 p0q1 p1q1
p1q2 . . . p7q7 p7q0), where p0p1 . . . p7 and q0q1 . . . q7 are permutations of {0, 1, . . . , 7}
with p0 = 0 and q0 < q1 . Consequently there are 8!2/16 = 101606400 of them, if
symmetry isn’t taken into account. That cycle is equivalent to its transpose if and
only if pj = q(k-j) mod 8 for some k and all j; there are 8!/2 = 20160 such cases. It is
equivalent to its 180° rotation if and only if pj + p4+j = qj + q4+j = 7 for 0 < j < 4;
there are 6 • 4 • 2 • 8 • 6 • 4 • 2/2 = 9216 such cases. And it is equivalent to both, in
6 • 4 • 2 • 8/2 = 192 cases. Hence by “Burnside’s lemma” there are (101606400 + 0 +
9216 + 0 + 20160 + 0 + 20160 + 0)/8 = 12706992 equivalence classes of rook cycles.
[T. R. Dawson introduced this problem for knights, and presented an example
path of length 31 and an example cycle of length 32, in L’Echiquier (2) 2 (1930), 1085;
3 (1931), 1150. C. C. Verbeek posed the problem of maximizing the number of queens
such that each is “attacked by exactly two others” in Elsevier’s Weekly (June 1971);
if we allow several queens in the same row, arguing that the first doesn’t attack the
third, 14 queens are actually possible (see P. Torbijn, Cubism For Fun 17 (1991), 19).
The name ‘snake-in-the-box’ was coined by W. H. Kautz, IRE Trans. EC-7 (1958),
177-180, for the case where G is an n-cube. The term ‘coil-in-the-box’ is often used
nowadays for a snake-in-the-box cycle.]
Nikolai Beluhov proved in 2018 that, if n > 6 is even, all snake-in-the-box king
paths of the maximal length n2/2 — 1 on n x n boards have an interesting structure,
which can be characterized completely. In fact, he showed that exactly 2n+(n mod 4)/2
July 26, 2019
170 ANSWERS TO EXERCISES 7.2.2.1
such paths are distinct under symmetry. Furthermore, there are exactly six distinct Beluhov
snake-in-the-box king cycles of length n2/2 — 1, when n > 8 is a multiple of 4. author
Nacin
With arguments of a different kind, Beluhov has also proved that the longest SAT solver
snake-in-the-box paths and cycles of a knight, on an m x n board, have length mn/2 — rainbow puzzles
O(m + n). [To appear.]
173. (a) Write ‘k ——— ij’ if clue k is a (knight or bishop) move away from cell (i, j).
For each row, column, and box, compute “quotas” ri , cj , and bx , equal to 3 minus the
number of pieces already present among the given clues. Also compute the quota pk for
each clue k, equal to the label minus the number of neighboring cells already occupied.
There is no solution if any quota is negative.
Say that cell (i, j) of box x is known if it is occupied, or if ri = 0 or cj = 0 or
bx = 0, or if pk = 0 for some k ——— ij. Introduce primary items Ri, Cj , Bx , Pk for each
row, column, box, or clue with a positive quota, having multiplicities ri, cj, bx, pk.
There is one option for each unknown cell, namely ‘Ri Cj Bx {Pk | k ——— ij}’.
(b, c, d) See Fig. A-6. The knight puzzles with labels > 6, and the bishop puzzles
with labels 0, 10, and 12, are due to N. Beluhov; the others represent the author’s best
early attempts, not necessarily minimum. Solutions can be found in Appendix E.
_ _ш.
it it it it it it it i4 i4 it it it it
it it it it it it it it it it
it it it it it ft
it
it it it it
it
|4
it
[These variants of sudoku were devised by David Nacin and first published in
MAA Focus 38, 6 (Dec. 2018/Jan. 2019), 36; see also quadratablog.blogspot.com.]
[Also shown are his 10-clue puzzles in which all the labels are equal.] secondary items
color
175. We can allow an option a to be repeated twice by simply replacing it by three 0123-mtx
options ‘a x’, ‘# x’, ‘# a’, where # is a new primary item and x is a new secondary Wallis
item. (If a contains uncolored secondary items y1 , . . . , ys , we should first replace them
by y1:c, . . . , ys:c, where c is a new color.)
In general if a is the ith option and if ai = a + 1 > 1, replace a by the 2a + 1
options ‘a x1i’, ‘#1i x1i ’, ‘#1i a x2i’, ‘#2i x2i ’, ‘#2i a x3i ’, . . . , ‘#ai xai’, ‘#ai a’,
where #ti and xti are new primary and secondary items.
176. (a) Introduce 3N items {Aj, Bj, #j | 1 < j < N}, to be used in M options
{Aj | aij > 1} U {Bj | aij = 2} for 1 < i < M. (For example, the option for row (2, 1,
0, 2, 0, . . . ) would be ‘A1 B1 A2 A4 B4’.) Add 2N further options ‘#j Aj’, ‘#j Bj ’ for
1 < j < N. Use Algorithm M with multiplicities (2, 1, 1) for (Aj, Bj , #j).
(b) The same construction works, but with multiplicities (3, 1, 1).
(c) Now use 4N primary items {Aj, Bj, #j, #j} and N secondary items xj.
Change the 2N special options to ‘#j Aj’, ‘#j Bj xj’, ‘#j Aj xj’, ‘#j Bj’, for
1 < j < N. Use multiplicities (4, 2, 1, 1).
(d) With 7N primary items {Aj, Bj, #1j, . . . , #5j} and 4N secondary items
{X1j , X2j , X3j , X4j }, the special options are ‘#1j Aj’, ‘#1j Bj X1j’, ‘#2j Aj X1j’, ‘#2j
Bj X2j’, . . . , ‘#5j Aj X4j’, ‘#5j Bj’, and the multiplicities are (11, 5, 1, 1, 1, 1, 1).
177. (a) The 2s3t - 1 nonzero vectors a1 . . . asb1 . . . bt with 0 < ai < 1 and 0 < bi < 2
form the rows of a matrix A. Allow the 2t - 1 rows with ai = 0 and bi = 2 to be
repeated, via answer 175; also encode the 2’s via answer 176. That leads to s+3t+2t - 1
primary items, 2t - 1 secondary items, and a total of 2s3t - 1 + 2t + 2(2t - 1) options.
(There are 91914202 multipartitions when s = t = 5. Algorithm M generates them at
a rate of about 1300 mems per solution; that’s only about seven times slower than the
special-purpose Algorithm 7.2.1.5M.)
(b) This problem is easier, because we simply disallow using an option twice.
That leaves us with s + 3t primary items and 2s3t - 1 + 2t options.
(Exercise 7.2.1.5-73 enumerates the number of solutions P(s,t) for part (a). The
same argument gives a similar recurrence for the number Q(s, t) of solutions to part (b):
With this formula one finds quickly, for example, that Q(5, 5) = 75114998.)
178. (a) Since 360 = 23 • 32 • 5, we need first to extend exercise 176 to matrices of
0s, 1s, 2s, and 3s. Encoding aij = 3 in option i can be done by using items Aj , Bj ,
Cj. To ensure a total of 3 in that column, let #j and #j be new primary items, and
give multiplicity (3,1,1,1,1) to (Aj, Bj, Cj, #j, #j); also let xj be secondary. Then
the special options ‘#j Aj’, ‘#j Bj xj’, ‘#j Aj xj’, ‘#j Cj ’ will fix everything up.
This makes an MCC problem with 29 options, 9 + 1 items, and 34 solutions.
(b) Now use exercise 175 to allow the options for factors 3 and 2 x 3 to be repeated
at most twice, and to allow the option for factor 2 to be repeated at most thrice. The
MCC problem now has 37 options, 13+5 items, and 52 solutions. [These solutions were
first studied by John Wallis; see exercise 7.2.1.7-28.]
179. From 1000 + 0110 + 0001 we get four solutions 100000 + {011100, 011100} +
{000011, 000011}; from 1110 + 0001 we get two solutions 111100 + {000011, 000011};
and from 1010 + 0101 we get 101000 + 010111.
July 26, 2019
172 answers to exercises 7.2.2.1
180. The text showed that o1 = ‘i1’ and that i2 and o5 exist, when t = 4 and t' > 1. restricted growth strings
Continuing that example, if s2 = 5 so that t' > 2, then option o2 intersects only differential equation
tail
{o1, . . . , o5}; hence o2 = ‘i1 i2’, and i2 cannot occur in more than 4 options. Its equivalence relations
appearances must therefore be in {o2 , o3, o4, o5}. Moser
Guy
Furthermore, o3 must be ‘i1 i2 i3 . . . ’ for some third item, i3 , since we can’t have
o3 = o2 . Consequently there’s an option o6 = ‘i2 i3 . . . ’. And so on.
181. (c0, c1 , c2 , c3, c4) = (188, 248, 320, 425, 566)/96, by the initial values in the text.
(To establish the lower b ound in Theorem E,
make n copies of this problem, on disjoint
four-tuples of items. This yields 7n solutions,
in a search tree with (5 • 7n — 3)/2 nodes. No
tice that the branching factor never exceeds 3
in this construction.)
183. (Can one, for example, often make the branching factor t = 4?)
184. Yes. If we can write t = an-1 wn-1 + an-2wn-2 + ••• + a0~0, with 0 < aj < (n- 1)
for 0 < j < n, we get such a problem by letting the options consist of (i) all 2n-1 — 1
subsets of {1, . . . , n— 1}; (ii) exactly aj subsets of {1, . . . , n} of size n—j that contain n.
To write t in that form,, suppose t = fn -1)wn-1 + ••• + ( n-1Wn-k+1 +
n-1 n- n-k+1 n- +
an-k~ n k + t, where 0 < an-k < (n~1) and 0 < t' < wn-k. Then, by induction, we
can write t' = an k i~n i k + ••• + a0ro0, with 0 < aj < (” k 1) < (nj. 1).
For example, 10000 = 14140+6^877+(b203 + 7^52 + 2•15+(0• 5 + (0^2 + (b 1)))).
185. We get the most solutions when we have the most options, namely the 2N1+N2 —
2N2 subsets that aren’t entirely secondary. Then the solutions are the set partitions
that include at most one entirely secondary block; and the number of such set partitions
is seen to be m Nm1 (m + 1)N2 , when we consider their restricted growth strings.
186. (a) The list for i consists of all 2n 1 subsets that contain i. So there are nk 11
N. J. A. Sloane; see OEIS sequences A046936 and A298804. If we start with ‘0, 0, 1’ on Sloane
the diagonal instead of ‘0, 1’, we get Gould’s (an2) = (0, 0,1,1, 4,14, 54, 233,...); etc.] OEIS
Gould
189. (a) |eez| = |excosy+ixsiny| =exp(xcosy); |e-ez| =exp(—xcosy). Asakly
Blecher
(b) | f0 exp(—e5^) d(£e^) + f/e-etdt\ = O(£ exp(—excos y)) + O(exp(—e5)); Brennan
Knopfmacher
|ee | = O(exp(e5)); and we have x = £ cos в > £ — 2.25/£, cos y > cos 2. Mansour
(c) We have /' e-eetdt = e-eetdt — f1 e-euzd(uz) = g/3 — I. Let max |eeuz Wagner
|
z 00 Euler
for 0 < u < 1 be exp(—eu0x cos u0y). If cosu0y > 0 we have |I| = O(£). Otherwise divergent series
if cos y — cos u0y < 1 we have |ee 11 < £ exp(ex cos y — eu0x cosu0y) < £ exp(ex cos y — Gompertz
ex cosu0y) < £exp(ex). Otherwise we use a more delicate argument: Since cos(a — b) — Gamma function
Trading tails
cos(a + b) = 2(sin a)(sin b), we have | sin u02-1 y| = 12 |(cos y — cos u0y)/ sin u02+1 y| > 12 , Somos
hence u0 < 1 — n/(3y). And in this range, u0x < x — 3x/y = £ cos в — 3 cot в < OEIS
£ — c£1/3 + O(1), where c3 = 3n2.
The desired bound now holds in each case because x = £^/1 — sin2 в < £ — 9/(8£).
(d) If п < в < n, \eez | exp(—eu0x cos u0y) = O(1). Since pn-1 /(n — 1)! =
2ni fR(z) dz/zn, and since wn-1/(n—1)! = ©(eeV^n-VIn)) by 7.2.1.5-(26), we have
|рп-1/шп-1| = O(V£n exp(—C2e5/£)) for all C2 < 9. And — e5/£ = —n/£2 < —n/ln2n.
[These results, and considerably more, were proved by W. Asakly, A. Blecher,
C. Brennan, A. Knopfmacher, T. Mansour, and S. Wagner, J. Math. Analysis and Ap-
plic. 416 (2014), 672-682. In particular, they proved that a„k/~„ rapidly approaches
the constant gk = /0'' tk-1e1-etdt/k! = J0'' e-x lnk(1 + x) dx/k!, for all k > 0.]
Historical notes: Leonhard Euler computed the constant g when he argued that
this value can be assigned to the divergent series n/=0(—1)nn! [Novi Comment. Acad.
Sci. Pet. 5 (1754), 205-237]. Benjamin Gompertz, who did not know the constant gg
explicitly, studied the probability distributions F (x) = 1 — a1-bx for a, b > 0 and x > 0
[Philos. Trans. 115 (1825), 513-585]. His name came to be associated with gg because,
for example, a random variable with a = e in his distribution has E X = gg/ln b.
190. Empirically, these signs are essentially periodic, but with a slowly
increasing period length as n grows. For example, the signs for 4000 <
n < 4100 are +2 —4+4 — 5+4—4+5—4+4 — 5+4—4+4 — 5+4—4+5— 4+4 — 5+4
—4+4 —5. The quantities ink — g~„k for 1 < k < n < 100 have the
interesting sign pattern shown at the right. (See exercise 188.) Complex
variables are evidently interacting here somehow!
191. The mean is G' (1) = 1 + g; the variance is G"(1) + G' (1) — G'(1)2 = 2g2 + g — g2 «
0.773. [Incidentally, G(z) can also be written eF(1 + z) — /= /=1(—1)kez/((k + z)k!).]
192. Let £e5 = n as in 7.2.1.5-(24). Then, when x = e5 — 1 +1 and t is small, we have
e-x(ln(1 + x))n « Aexp( —(1 + £)t2/(2n)), where A = exp(nln£ + 1 — e5). Trading
tails and integrating over — to < t < to gives gn ~ Ay7 2nn/(1 + ^) /n!.
193. At level 0, when given the complete graph Kt+1, the algorithm does t+ 1 updates
when covering i in step X4, and t updates when covering each of t values of j in step X5.
Thus U(t + 1) = 1 + t + t2 + tU(t — 1).
194. (a) In general we have X(2q + 1) = (2q)(2q — 2).. . (2) (a0 + a2/2 + a4/(2 • 4) + • • • +
a2q/(2 • 4•. .. • (2q))) = 2qq!S — R, where S = 22n>0 a2n/(2nn!) and R = a2q+2/(2q+2) +
a2q+4/((2q+2) • (2q+4)) + • • •. Hence when at = 1 we have S = e1/2 and 0 < R < 1.
[This result was noticed in 1999 by Michael Somos; see OEIS A010844.]
(b) In general, X (2q) = ((2q)!/(2qq!))S — R, where S = X(0) + a1 + a3/3 +
a5/(3 • 5) + a7/(3 • 5 • 7) + • • • and R = a2q+1/(2q+1) + a2q+3/((2q+1) • (2q+3)) + • • • .
July 26, 2019
174 ANSWERS TO EXERCISES 7.2.2.1
200. (a) When all n3 options are present, det Q(X) = sign(p)v1p1q1 . . . vnpnqn , inclusion-exclusion principle
summed over all permutations p = p1.. .pn and all n-tuples q = q1 ... qn with qj / X. prime
BjOrklund
Summing (-1)|X | det Q(X) yields sign(p)v1p1 q1 . . . vnpn qn where both p and q are circular table
permutations. (This is essentially an application of the inclusion-exclusion principle.) Lucas number
Set vijk ^ 0 if option ‘ai bj ck’ isn’t present.
(b) Assign a random integer in [0 . . p) to each of the M given options, where p is a
prime greater than 2M , and evaluate s = S mod p. If s = 0, S is nonzero. If s = 0, S is
nonzero with probability less than 1 — (1-1/p)M < M/p < 1/2, by exercise 4.6.1-16,
because S is linear in each variable. Repeating r times will fail with probability < 2-r.
[In practice, 2n is often an overestimate because many of the determinants are
obviously zero. For example, if Q(X) has an all-zero row or column, so does Q(X') for
all X' D X. This method shines on unsolvable examples such as those of exercise 199.
Bjorklund’s paper, STACS 27 (2010), 95-106, has more general results.]
201. (a) “Given n people seated at a circular table, how many seating arrangements
do not require anyb ody to move more than one place left or right?”
(b) Two solutions in which everybody moves, plus Ln solutions (a Lucas number)
in which at least one person remains in the same seat.
(c) An interesting recursive structure leads to the answer 5Ln+2 + 10n - 33. [This
analysis depends on using the given ordering to break ties in step X3 when several lists
have the minimum length.]
203. (a) Yes; T ф T' ф T" is the search tree corresponding to A ф A ф A".
(b) No; J = J ф J = J ф J = J.
(b) Include two new fields, act and stamp, initially zero, in each item node. stamp (time stamp)
(They can share an octabyte, if act is a short float and stamp is a tetrabyte.) A short float
multiplicity
global variable time serves as the “convenient clock.” Another global, bump (which nonsharp preference
is a short float, initially 10-32), is the amount by which we advance activity scores. bitriples
biquadruples
Whenever i is covered or uncovered, or whenever len(i) is changed, we check to see if
STAMP(i) = TIME; if not, we set ACT(i) ^ ACT(i) + BUMP and STAMP(i) ^ TIME.
The “clock” advances at the beginning of steps X4, X5, X6, and X7. This means
that TIME ^ (TIME + 1) mod 232 and BUMP ^ BUMP/p. (Furthermore, if BUMP > 1029,
we divide BUMP and all ACT fields by 1064, to avoid overflow. We limit p to be at most
.999, so that each ai is at most 1000.)
These changes allow us to replace the definition of A in step X3 (answer 9) by
A ^ (LEN(p) < 1? LEN(p): 1 + LEN(p)/(1 + мACT(p)/BUMP)).
(c) Consider (go) first. After branching on 00 and trying option ‘00 01’, we have
a00 = a02 = p, a01 = 1 + p, a04 = a05 = a06 = 1, and the other a’s are zero. We want
A05 = 1 + 3/(1 + ма05) to be less than A10 = 1 + 2; that is, м > 1/2. Later, after trying
option ‘00 02’, we’ll have a05 > 1 and a06 > 1; again, item 01 isn’t chosen.
Problem (g2) is trickier. After trying ‘00 01’, the nonzero a’s are a00 = a02 = p,
ao1 = 1 + p, and ao3 = ao4 = ao5 = 1. We’ll prefer the 3-way branch on 02 to the
2-way branch on 20 if м > 1/(2p); and we’ll even prefer the 4-way branch on 04 (or 05)
to that 2-way branch, if м > 1. In either case we’ll reach a solution to problem 0 before
starting on problem 1. The same calculations then take us to problem 2 only when
problem 1 has been solved; etc. (Furthermore, when coming back down there will be no
incentive to go back up. In fact, 4-way branches will be done on the items k3 because
of their high activity scores.)
(d) The normal Algorithm X finds all 212 solutions in 96 Gm, with a 55-meganode
search tree. This modification finds them in 51 Gm, if we set м = 1/8 and p = .99, with
a 26-meganode search tree. (With м = 1/2 and p = .9, the time is 62 Gm. In long runs,
the a scores tend to approach 1/(1 - p); so increases in p usually imply decreases in м.)
208. The original problem has primary items ij for 0 < i, j < e, and eight kinds of
options ‘{ij + S | S G Sk}’ for all cells ij + S that are in range, where So = {01,11,
21, 31, 10}, S1 = {00, 01, 02, 03, 11}, S2 = {00, 10, 20, 30, 21}, S3 = {10, 11, 12, 13, 02},
S4 = {01, 11, 21, 31, 20}, S5 = {00, 01, 02, 03, 12}, S6 = {00, 10, 20, 30, 11}, S7 =
{10, 11, 12, 13, 01}. Options that involve the center cell 77 come only from S0.
The modified problem adds secondary items Vij and Hji , for 0 < i < b, 1 < j < d.
,
It inserts Vi(j-1) , H(i+1)j Vi(j+1) , respectively into the options with S4, S5 , S6, S7.
(The 16 solutions to this problem represent 22 + 24 + 25 + 22 + 23 + 22 + 25 +
23 + 25 + 23 + 22 + 24 + 23 + 24 + 22 + 24 = 212 solutions to the original. We’re lucky
that none of those solutions has an ‘H’ that includes 77.)
209. With the modified options ‘0 1 A’, ‘0 2 B’, ‘14 5 B’, ‘2 3 4 A’,
obtained from the bipairs (‘0 1’, ‘2 3 4’; ‘0 2’, ‘1 3 4’) and (‘0 1’, ‘2 4 5’;
‘0 2’, ‘1 4 5’), we get the balanced search tree shown here. ■ • • •
210. Add a new primary item #A and give it multiplicity [0 . . 2]. Insert it into options
а', в, Y'. Then use the nonsharp preference variant of Algorithm M.
211. No bipairs. (But Langford has bitriples, and all three have “biquadruples.”)
212. (a) Order the options first by their smallest item, and secondly by lexicographic
order among those with the same smallest item.
(b) Yes. For example, we can let 1 < 2, and 1 < 4 < 0 < 5.
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 177
213. Yes, provided that we regard a proper prefix of a string as lexicographically larger prefix of a string
than that string (contrary to the conventions of a dictionary). Otherwise the condition reachability problem
acyclic digraph
fails when a is a prefix of a' (although exercise 212 remains valid). sinks
Suppose the items of a and в are respectively represented by the digits j and k 2DM
4-cycles
in rgs(n), the restricted growth string of n. Then j will also represent a' in rgs(n'), author
and both strings will be equal up to the point where j first appears.
Let в be represented by k' in rgs(n'); then k' > j. Consider the leftmost place
where rgs(n) differs from rgs(n'). If that digit is j in rgs(n), it is k' in rgs(n'). Otherwise
it is k in rgs(n); but then it is j in rgs(n'), and a is a prefix of a'.
214. We can find all solutions S that reduce to a given strong solution S0, by repeat
edly reversing the construction in the proof of Theorem S — replacing joint occurrences
of a and в by joint occurrences of a' and в', for all canonical bipairs, in all possible ways.
(It’s a reachability problem: to find all nodes of an acyclic digraph, given the sinks.)
Notice that different strong solutions can lead to the same nonstrong solution. For
example, in the 2DM problem with options {xX, xY, yX, yY, yZ, zY, zZ}, where uv stands
for ‘u v’, we might have the canonical bipairs (yX, xY; yY, xX), (yZ, zY; yY, zZ). The
strong solutions {xY, yX, zZ} and {xX, yZ, zY} both lead to the nonstrong {xX, yY, zZ}.
(However, in that same problem, we could have made the bipairs (yX, xY; yY, xX),
(yY, zZ; yZ, zY) canonical. Then there would have been only one strong solution.)
215. (a) This is the number of 4-cycles, of which there are 3 2q4+1 : Four vertices
i < j < k < l can form three 4-cycles, with either j or k or l opposite i.
(b) For convenience, denote options by ij instead of ‘i j’. If i < j < k < l, we
exclude (i, j, k, l) unless min(ij, ik, il, jk, jl, kl) = ij or kl. We exclude (i, k, j, l) unless
min(ij, ik, il, jk, jl, kl) = ik or jl. We exclude (i, l, j, k) unless min(ij, ik, il, jk, jl, kl) =
il or jk. Hence exactly two of the three possibilities are excluded.
(c) When i < j < k < l they are (i, k, j, l) and (i, l, j, k).
(d) The root has 2q children, branching on 0. All of them are leaves except for
the branch ‘0 1’. That one has 2q - 2 children, all of which are leaves except for the
branch ‘2 3’. And so on, with 2(q - l) nodes on level l > 0.
(e) For i < j , use only (i, j, k, l) for i < k < min(j, l) and (k, l, i, j) for k < i < l.
(f) Put ‘1 2q’ first, then ‘2 2q-1’, . . . , then ‘q q+1’, then the others. When we
branch on ‘0 k’ at the root, for 1 < k < 2q, no options remain for item 2q + 1 — k.
(g) ‘0 k’ and ‘2q+1 —k l’ are excluded, for all l / {0, k, 2q+1 — k}. (Altogether
(q — 1)(q — 3) cases.) [Is it perhaps feasible to order the options dynamical ly ?]
216. The search tree is almost always smaller than that of answer 215(c), which in fact
has the worst case on every level. But it rarely seems to go below half of the worst-case
size. (The author discovered the trick of answer 215(f) by studying randomly generated
examples that had unusually small trees.)
Algorithm X needs 540 G// to prove that K21 has no perfect matching. It has
potentially 2 241 = 11970 excludable quadruples. We can use Algorithm 3.4.2S to
sample just m of them; then the running time for m = (2000, 4000, 6000, 8000, and
10000) decreases to about (40 G^, 1.6 G^, 145 M^, 31 M^, 12 M^), respectively.
217. Each delta a — a' has k positive terms and k negative terms; we can assume that
1 < k < 4. Furthermore it suffices to work with “normalized” deltas, which are lexico
graphically smallest under rotation, reflection, and negation. The pentominoes (O, P,
. . . , Z) have (10, 64, 81, 73, 78, 25, 23, 24, 22, 3, 78, 24) normalized deltas, of which (1, 7,
3, 3, 2, 0, 1, 0, 1, 0, 4, 0) have k = 1. Two of the deltas are shared by four different pen-
tominoes: 00+01 — 23— 33 (Q, S, W, Z); 00— 02 (P, Q, R, Y). Eleven are shared by three.
July 26, 2019
178 ANSWERS TO EXERCISES 7.2.2.1
A common delta is necessary but not sufficient; if a — a' = в' — в, we still need to Miller
fill in cancelled terms that don’t clash. For example, 00 - 23 is common to Q and W, naked pairs
sudoku
but it doesn’t yield a bipair. Furthermore (although the exercise didn’t state this!), we spacers
don’t want the 10-cell region to have a hole; the delta 00 + 01 — 12 — 22 is common to P, commit’
U, and Y, but only PY makes a useful bipair. A delta can arise in more than one way:
From 00 + 01 + 02 + 03 — 20 — 21 — 22 — 23 we can make a Q with either 10 or 13, and
a Y with either 11 or 12; symmetry (and hole removal) yields only one bipair, not four.
The complete catalog has 34 essentially distinct entries. Eighteen of them
have 10-cell shapes with left-right symmetry. Fourteen have transposition symmetry:
The other two are especially interesting because they are asymmetric:
TM?‘ -^
(These two each lead to eight varieties when rotated and reflected, not just four. See
J. C. P. Miller in Eureka: The Archimedeans’ Journal 23 (1960), 14-15.)
218. If the only options involving p are ‘p i:0’ and ‘p i:1’, we can’t eliminate item i.
[But if they all involve, say, i:0, we could eliminate it; Algorithm P doesn’t go that far.]
219. If option o contains i, but neither p nor q, it can be in a solution only with two
other options {o', o"} that contain {p, q}. But o' and o'' must then both contain j.
[This argument is like the “naked pairs” of sudoku lore. It’s tempting to go further, by
also eliminating items i and j ; but that could increase the number of solutions.]
220. Let the option be ‘i1 i2 [:c2] . . . it [:ct]’. We’ve already covered item i = i1 , which
is represented by node x. Nodes x+1, x+2, . . . represent the other items, possibly with
spacers that were inserted when this option was shortened (see exercise 222). We want
to commit i2 , . . . , it , and to determine whether this causes len(p) to become 0 for some
primary p / {i2,... ,it}. The tricky part is to be sure that p / {i2,. .. ,it}; to accom
plish this, we set COLOR(ij) ^ x for 1 < j < t. [In detail: Set p ^ x + 1; while p > x,
set j ^ TOP(p), and if j < 0 set p ^ ULINK(p), otherwise set COLOR(j) ^ x, p ^ p +1.]
Then we make a second pass over the option: Set p ^ x + 1. While p > x, set j ^
TOP(p), and if j < 0 set p ^ ULINK(p), otherwise commit'(p,j) and set p ^ p +1. Here
commit'(p, j) emulates (54): Set c ^ COLOR(p), q ^ DLINK(j); while q = j, hide'"(q)
unless COLOR(q) = c > 0, and set q ^ DLINK(q). And hide'"(p) is just like hide(p), but
it detects blocking if len(y ) becomes 0 for some y < N1 with color(y) = x.
Finally, a third pass undoes our changes: Set p ^ x — 1. While p = x, set j ^
TOP(p), and if j < 0 set p ^ DLINK(p), otherwise uncommit'(p, j) and set p ^ p — 1.
Here uncommit'(p, j) undoes commit'(p, j) in the obvious way.
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 179
It is possible to switch immediately from committing to uncommitting as soon as jumping into the middle of a loop
blocking is detected, by jumping into the middle of a loop (see answer 122). spacer
author
221. While S > 0, set x ^ S, S ^ TOP(x), TOP(x) ^ i, and do the following: Set
q ^ x; while q > x, set j ^ TOP(q), and if j < 0 set q ^ ULINK(q); otherwise if j < N1
and LEN(j) = 1, go to P9; otherwise set u ^ ULINK(q), d ^ DLINK(q), ULINK(d) ^ u,
DLINK(u) ^ d, LEN(j) ^ LEN(j) - 1, q ^ q + 1.
222. Set p ^ DLINK(i), and do the following steps while p = i: Set p' ^ DLINK(p),
q ^ p +1. While q = p, set j ^ TOP(q), and if j < 0 set q ^ ULINK(q); otherwise if
j = S, exit this loop; otherwise set q ^ q +1. Then if q = p, set ULINK(p) ^ p + 1,
DLINK(p) ^ p — 1, TOP(p) ^ 0 (thereby making a spacer); otherwise set q ^ p + 1 and
perform the loop in answer 221 while q = p (instead of while q > x). Finally set p ^ p'.
223. In accordance with the conventions of exercise 8, we first declare the items of the
reduced problem: For 1 < i < N , output the distinguishing mark for secondary items,
if i = N1 + 1; and output the name of item i, if len(i) > 0 or i = N = 1. Then we
output the remaining options: For 1 < i < N, if LEN(i) > 0, set p ^ DLINK(i) and do
the following while p = i: Set q ^ p — 1 and while DLINK(q) = q — 1 set q ^ q — 1. If
top(q) < 0 (hence i was the leftmost item to survive, in the option following the spacer
node q), output the option as explained below. Then set p ^ DLINK(p) and repeat.
To output the (possibly shortened) option that follows node q, set q ^ q + 1;
then, while top(q ) > 0, output the name of item top(q ) if top(q ) > 0, followed by :c
if COLOR(q) = c > 0, and set q ^ q + 1. (Afterwards, —TOP(q) is the number of the
corresponding option in the original input.)
224. Use 3n — 3 items p1 , x1 , i1 , . . . , pn-1 , xn-1 , in-1 (in that order), with the options
‘in-k pk xk’, ‘in-k pk xk+1’, ‘in-k xk’, ‘in-k pk+1’, for 1 < k < n — 1, and also ‘i1 pn-1
xn-1’, ‘i1 xn-1’. During round k, for 1 < k < n, item in-k is forced by pk.
225. Some options, like ‘Z 01 02 11 20 21’ and ‘U 30 31 41 50 51’, are obviously useless
because they cut off a region of fewer than five cells. More of these options are discarded
in the larger problem — but only because of piece U. Eight options, like ‘O 10 11 12
13 14’, are useless because they block a corner cell.
The smaller problem also has numerous options like ‘P 02 12 13 22 23’, which
turn out to be useless because they block piece X. (That piece has been confined to
just eight placements, in order to break symmetry. It has more freedom in the larger
problem, and can’t be blocked there.) Round 2 also discovers that options like ‘O 22
23 24 25 26’ would block X, since round 1 has disabled one of X’s eight choices.
226. Since 21 52k=1(2n + 1 — k)ak, it’s clear that 21 + 21 = (2n + 1) 52k=1 ak =
(2n + 1)(n + 1)n. Similarly S + S' = (2n + 1) 52k=1 ak = (2n + 1)2(n + 1)n/3-
The relation 22 — (2n + 1)2'1 = 22 — (2n +1)21 holds for any sequence a1... a2n.
227. (a) $(ij2 + ik2). (b) $(i2j + i2k). [$(C — ij2 — ik2), for large C, will maximize 22.]
228. Well, it certainly surprised the author. Intuitively, we expect small 21 52 kak
to be correlated with small 22 = k2ak , but not nearly so well. For some mysterious
reason, Langford pairings with the same 21 tend to have the same 22 , and vice versa!
That’s not always true. For example, 2 8 6 2 3 5 7 4 3 6 8 5 4 1 7 1 and 3 5 7 4 3 8 6 5 4
1 71 2682 have the same 21 but different 22; 151 74895 1141076382932611 10
and 1 4 1 6 7 10 4 5 9 11 6 8 7 5 2 3 10 2 9 3 8 11 have the same 22 but different 21. Yet such
exceptions are rare. When n = 7, the four pairings that have 21 = 444 are the same as
the four that have 22 = 4440; the six pairings that have the larger value 21 = 448 are
the same as the six that have 22 = 4424, which is smal ler than 4440. What is going on?
July 26, 2019
180 ANSWERS TO EXERCISES 7.2.2.1
The special nature of Langford pairings does allow us to prove certain curious minimax
facts. For example, let jk be the index of the first occurrence of k. The other occurrence author
rounding errors
is at jk + k + 1; hence ^2n=1 jk = (3n - 1)n/4 Also 12n=1 jk = (4nk - 1)n/3 - kSi. truncation errors
rooks
229. These pairings can be found by Algorithm 7.2.2L (or its reverse-order variant).
But we can also find them via dancing links, using the sharp minimax modification
of Algorithm X (or C) in exercise 85: Order options (16) so that ‘i sj sk’ precedes
‘i' Sj/ sk/’ when j' < j, or when j' = j and i' < i (for lex max) or i < i! (for lex min).
Then repeatedly (i) use the minimax algorithm to fill the smallest undetermined slot
sj ; (ii) move the option that minimally covered sj to the front of the list, and remove
all other options that involve sj .
Thus we find 12132483121341014151689611571210136591471511 16 in
sixteen such steps, all of which are easy (and need less than 110 K^) except for the
placements of 8 in s7 (4.5 M^) and 12 in s9 (500 K^). The total time (6 M^) includes
465 K// just for inputting the data in step X1. After placing 8 items, only 12 solutions
remain, so it’s slightly faster to switch gears when finishing. (This pairing has Si =
$5240, Sk = $119192, S = $60324; somewhat high but not extreme.)
The lexicographic maximum turns out to be (108)—partially explaining why it
is so “remarkable.” It can be obtained in the same fashion, in fewer than 2 M^.
230. Assume that all solutions to the exact cover problem contain the same number of
options, d. (For example, d = 16 in Fig. 74.) Then we can replace each cost $c by the
complementary cost, $(C - c), where C is sufficiently large to make this nonnegative.
Solve the problem with the complementary costs; then subtract its total cost from Cd.
[It’s convenient to implement a special version of Algorithm X$ that does this automat
ically, with appropriate changes to the presentation of intermediate and final results.]
231. (a) maple (b) happy (c) jambs MAGMA
ARRAY ($139); EXILE ($176); EQUIP or EQUIP ($197).
SMOKE ALLOW TUMOR OUNCE
TYPES PELTS SASSY WAKED
Algorithm X$ needs 6 G^, 80 G^, and 483 G// to find these; Algorithm X needs 5 G^,
95 G^, and 781 G// to visit all solutions, of which there are 27, 8017, and 310077. (Sec
tion 7.2.2’s trie-based methods are much faster: They need just 12 M^, 628 M^, 13 G^.)
232. No. The author actually did just that, in his first experiments; and he was
lucky, because the algorithm not only gave the same optimum placements, it also took
significantly less time — only 1.5 G// and 0.2 G//. However, the minimum cost ($182)
and maximum cost ($202) were just $1 different from the next-best costs! The effects
of 16 rounding errors, each potentially changing the result by nearly $1, could have in
validated everything. [Therefore the author used $|_23kd(i, j)J when preparing Fig. 74.]
233. With costs $|_232 lnd(i, j)J, we get the same answers (but faster: 1.2 + 0.2 G^).
234. By that measure, every placement of n nonattacking queens (or rooks!) costs
A, „ „.(„k_ 1)
((k - c)k + (pk - c)k) = 2 (k - c)k = 6 , where c = (n + 1)/2.
k =i k =i
235. Now the roles are reversed: We’re more interested in the periphery than in the
center, and the minimum is easier to compute than the maximum. The minimum cost,
$127760, is achievable in four ways, each symmetric; hence we must take K = 17, not
K = 9. This computation took only 1.3 G//. (The two examples below have different
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 181
sets of distances, which coincidentally yield the same total cost.) But there’s a unique author
way to get the maximum cost, $187760, discovered (with K = 9) in 9.7 G^: integer programming
Fischetti
Minimum У d4 Maximum У d4
236. The idea is first to minimize the longest distance; then, placing a queen at that
distance in all possible ways, to minimize the next-longest distance; and so on. In other
words, if the options are in nondecreasing order by cost, it’s almost like the search for
lexicographically minimax solutions, iteratively as in answer 229.
However, there’s a catch: Many options have the same cost. Different orderings of
equal-cost options can lead to wildly different lex-min solutions. For example, suppose
there are four options, ‘1’ for $1, ‘2’ for $2, ‘1 3’ for $3, and ‘2 3’ for $3. In that order,
the minimax solution omits the final option and costs 3N + 2N, which is not optimum.
The solution is to add to each option a primary item describing its cost, and
to use Algorithm M iteratively by specifying the number of queens of highest costs,
keeping this as low as possible until the problem has no solutions. Here are the best
such ways to place n queens, for n = 17, 18, and 19:
It appears likely that these optimum queen placements have rotational symmetry rotational symmetry
only when n = 1, 4, 5, 16, and 32. But the solutions for n = 64 and 128 do have 26 and slack
Gondran
212 equivalent mates, because they contain respectively 6 and 12 “tiltable squares” in Minoux
the sense of exercise 7.2.2-11(c). author
New England
(The limiting behavior may not “kick in” until N is quite large. For example, the depth-first search
optimum solution when n = 16 and N = 20 is not the symmetrical one illustrated; the
placements 811 4 7 5 12 116 14 2 15 10 3 13 6 9 have total cost ~ 2.08 x 1021, which beats
~ 2.09 x 1021. The limiting shape turns out to be optimum if and only if N > 21.)
237. False. For example, the square shown here is the smallest of ~ 3 billion 12113
solutions for which 02 = 20, 03 = 30, 12 = 21, 13 = 31, 42 = 24, 43 = 34. 11003
10103
1 1 3 2 1 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 10369
238. 3 0 7 1 0 3 1 1 0 3 0 1 1 0 0 1 0 3 1 0 0 04 0 3 31391
1 3 9 1 1 9 3 1 1 3 9 3 3 3 1 1 7 1 3 1 9 3 1 7 1J
1 1 1 1 1
9 9 7 8 9 9 9 9 8 9 9 9 9 8 9 9 9 9 9 8 9 9 9 9 9
7 8 7 8 6 9 9 9 8 8 9 7 9 8 8 5 7 9 9 8 6 8 5 9 7
7 3 3 7 7 1 7 7 7 3 1 7 7 7 3 3 7 1 7 7 7 3 3 1 7
The problems for n = 7 have 1759244 options; yet they were solved in 20 G// without
preprocessing. Special methods would, however, be required for n > 8.
239. Introduce primary items k and jk, for 1 < k < n and for all j with k G Sj. When
Sj = {k1, . . . , kt}, there’s an option ‘jk1 . . . jkt’ of cost wj , together with t options
‘ki jki’ of “infinitesimal” cost ei for 1 < i < t; also t “slack” options ‘jki’ of cost 0.
For example, suppose the only sets that cover 1 are S1 , S2 , S3 , S4; and suppose
that an optimum set cover uses S2 and S4 but neither S1 nor S3 . Then a maximum
cost solution to this exact cover problem will use option ‘11 . . . ’ of cost w1 , ‘31 . . . ’ of
cost w3, ‘1 21’ of cost б2, and ‘41’ of cost 0 (because the alternative with ‘21’ and ‘1 41’
has smaller cost e4).
[See M. Gondran and M. Minoux, Graphs and Algorithm (1984), exercise 10.35.
When finding the k best solutions instead of a single optimum, all solutions that become
identical when б is set to zero should be counted just once.]
240. Add {wy, co, nm} and either id orut or az. Or add {id, ut, co, ok}. Or add {sd, mo}
and either {ia, ok} or {ne, ar} (a surprise to the author when he posed this problem).
241. No, although it does find the cases where regions of fewer than 6 vertices are cut
off. Round 1 discovers that New England can be shrunk to a single item; then Round 2
is able to remove options such as ‘la ar tn va md pa’. Altogether 3983 options and
5 items are removed, at a cost of 8 G//.
242. Before visiting a solution in step R2', use depth-first search to find the connected
components of the residual graph. Reject the solution if any such component has a
size d for which d < L • [d/(U — 1)].
243. Let W = w1 + ••• + wn be the sum of all weights. Then we have ^2 k=1(xk - r)2 =
k k — 2rW + r2d, because
d =1 x2 kd=1 xk = W in an exact cover problem.
244. True: Let G have m edges and n vertices. A solution with k edges between verti
ces of the same option has total interior cost n(t — 1) — 2k, total exterior cost 2(m — k).
[But answer 246 shows that this can fail with options of different sizes.]
245. For (a), exercise 242 gives 42498 — 25230 = 17268 options of size 7. Minimum
cost $58 is discovered in 101 M^. For (b), there are 1176310 —1116759 = 59551 options
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 183
with population in [43 . . 45] million. In the optimum solution shown below, which was greedily
found in 7.7 G/л, all populations lie in the range [43.51 .. 44.24] million. sort
list merge sort
spacer
linear programming problem
dual
exact cover problem, fractional
Gondran
Lauriere
246. Minimum exterior cost ($90 and $74, found in 612 and 11 M^):
Minimum interior cost ($176 and $230, found in 1700 and 100 M^):
247. Use the procedure of answer 8 for raw data entry, but also set COST(j) ^ (the
cost of the current option) for p < j < p + k at the beginning of step I5.
Then assign taxes “greedily” by doing the following for k = 1, 2, . . . , n: If item k
has no options, terminate with an unsolvable problem. Otherwise let c be the minimum
cost of k’s options, and set COST(k) ^ c; this is the “tax” on k. If c > 0, subtract c
from the cost of every option on k’s list; this will affect all nodes of those options.
(The modified costs will be used internally. But all results reported to the user
should be expressed in terms of the original costs, by adding the taxes back in.)
After all taxes have been assigned, sort the options by their (new) costs. (The
“natural list merge sort,” exercise 5.2.4-12, works well for this purpose, with the COST
fields in spacer nodes serving as links.)
Finally, achieve (118) by re-inserting all nodes, in order of cost.
[Taxes could be assessed in many other ways. In general we seek real numbers u1,
... , un such that cj > {U{ii | item i in option j} for 1 < j < m, where u1 + • • • + un
is maximum. This is a linear programming problem, which happens to be dual to the
(fractional) exact cover problem of minimizing c1x1 + • • • + cmxm such that x1,. .. , xm >
0 and {xj | item i in option j } = 1 for 1 < i < n. An “optimum” taxation scheme,
found by a linear programming solver, might make Algorithm C$ significantly faster
than it is with the greedy scheme above, even on highly nonlinear XCC problems; careful
tests have not yet been made. See M. Gondran and J. L. Lauriere, Revue Francaise
d’Automatique, Informatique et Recherche Operationnelle 8, V-1 (1974), 27-40.]
July 26, 2019
184 answers to exercises 7.2.2.1
248. Set t ^ to, c ^ 0, j ^ RLINK(0), and do the following while j > 0: Set author
p ^ DLINK(j) and c ^ COST(p). If p = j or c > ft, go to C8$. Otherwise set s ^ 1, free ZDD
ordered ZDD
p ^ DLINK(p), and loop as follows: If p = j or COST(p) > ft, exit the loop; otherwise purify
if s = t, set s ^ s +1 and exit; otherwise if s > L, set s ^ LEN(j) and exit; otherwise header node
unpurify
set s ^ s + 1, p ^ DLINK(p), and continue. After exiting the loop, if s < t or (s = t
and c < c'), set t ^ s, i ^ j, and c ^ c. Finally set j ^ RLINK(j).
[The author uses L = 10. He considered doing a complete search, thereby avoiding
the frequent updates to LEN in (13), (15), etc.; but that turned out to be a bad idea.]
249. After we’ve seen t costs, we know only that the remaining dk - t are nonnegative.
The following algorithm sorts incoming costs into the rightmost positions of a buffer
b0b1 . . . bdk-1 , maintaining the best possible lower bound l: Set l = t = 0. When seeing
a new cost c, set p ^ t, r ^ 1, and do this while rp > 0: Set x ^ bdk-p. If c < x, set
r ^ 0. Otherwise if p mod k = 0, set l ^ l + x — y; set y ^ bdk-p-1 ^ x, p ^ p — 1.
After rp = 0, set bdk-p-1 ^ c, t ^ t + 1; if p mod k = 0, set l ^ l + c — y. Stop if l > 0.
250. Keep a separate “accumulator” for each character in Z, and another for z if it
is present. Look at each active item i: If name(i) begins with a character of Z, add
cost(dlink(i)) to the appropriate accumulator. Otherwise if z = 1, add that cost to
the accumulator for z. Otherwise if z > 1, use exercise 249 to accumulate costs that
are separated by z. If any of the accumulators becomes > T — Cl , go to C8$.
(When Z or z hints are given, step C1$ should verify that they are legitimate.)
251. When all items have been covered, step Z2 will see the signature S[0] = 0, which
was initialized in step Z1; Z[0] = 1 is the “success” node ‘T’.
252. 00 10
00 01 20 21
Notice that this free
ZDD is not ordered,
because ‘02 12’ appears
01 02 02 12
above ‘20 21’ in the left
11 21 branch but below ‘20
21’ in the right branch.
253. Introduce a global variable count; also auxiliary variables c0 c1 . . . indexed by the
current level l; also integer variables C[t] indexed by cache location t. Set COUNT ^ 0
and C[0] ^ 1 in step Z1. If a cache hit occurs in Z2, set COUNT ^ COUNT + C[t];
otherwise set cl ^ COUNT. Set C[ml ] ^ COUNT — cl in step Z7.
254. (a) If the options include d different colors for item i, a subproblem has d + 2
distinct cases: Either item i does not appear in any remaining options, or its list has
not been purified, or its list has been purified to a particular color. So we reserve
|"lg(d + 2)] bits for i in the signature. If, for example, d = 4, those three bits will
contain one of the codes 000, 001, 010, 011, 100, 101.
[In order to recognize the relevant case, Algorithm Z’s version of the ‘purify’
operation in (55) should set COLOR(i) ^ c in the header node for i; the ‘unpurify’ in
(57) should set COLOR(i) ^ 0; and step Z1 should set COLOR(i) ^ 0. That initialization
step should also remap i’s colors so that they appear internally as 1, 2,. . . , d.]
(b) In large problems a will occupy several octabytes. Give each item i a new
field sig(i), which is an index to a code table, and a new field wd(i). If len(i) = 0,
item i will contribute code[sig(i) + color(i)] to octabyte wd(i) of a.
July 26, 2019
7.2.2.1 answers to exercises 185
[If hashing is used for the cache lookup in step Z2, the code table can also contain hash function
random bits, for convenience in computing a good hash function.] hide" (p)
unhide"
(c) Operation hide'(p) doesn’t remove node q from list TOP(q), if that list has been
author
purified. But if top(q) is included in the signature, we’ll never get a cache hit for solu generating functions
tions with different colors, even when subproblems don’t actually depend on those col menage problem
MRV heuristic
ors. Therefore we need to know when a secondary item has no active options in its list. Lucas number
(d) The trick is to decrease len(i), while still retaining the nodes on list i. If
len(i) becomes zero, when i is a secondary item, we can then remove it from the list
of active secondary items (whose head is N + 1, by answer 8).
[We can also use this trick in the ‘hide’ routine: Let hide"(p) be like hide(p)
except that dlink(u) and ulink(d) remain unmodified when color(q) < 0; len(x) is
decreased as usual.] Of course unpurify and unhide" should undo purify and hide".
Some delicate maneuvers are needed to avoid deactivating a secondary item
twice, and to reactivate it at precisely the right time when unpurifying. (The author’s
implementation temporarily sets the len to -1.)
255. Let Vn = ЕП=о(п-1-2к)(n-k), Wn = ЕП=о(1 + (п-1-2к) + (п-1-2к)2)(n-k).
Using the fact that kn=0 kr n-k k = [zn] z2r/(1- z -z2)r+1, we obtain the closed forms
Vn = ((n-5)Fn+1 +2(n+1)Fn)/5 and Wn = ((5n2+7n+25)Fn+1 -6(n+1)Fn)/25. (See
the derivation of 1.2.8-(iy).) When N is even, Algorithm Z performs WN — 1 updates
and outputs a ZDD with VN + 2 nodes. When N is odd, it performs WN updates and
outputs the trivial ZDD ‘±’.
256. Let T (N), Z(N), and C(N) be the time, ZDD size, and cache size needed for
KN. With (8g) the algorithm first spends T(2q) + T(2r) time to create a ZDD of size
Z(2q) + Z(2r). Then it spends min(T (2q + 1), T(2r — 1)) time to learn that no more
ZDD nodes are desirable. The cache size is C (2q) + C(2r) + min(C(2q + 1), C(2r — 1)).
257. (a) There are 2n-1+1 signatures: 11 . . . 1 and all n-bit strings beginning with 0.
Each nonzero
signature a
has 2VCT-1
branches.
258. See (84). Nowit’s Vn = Vn + En-11 (”- 1)vk = ((72n — 342)5n + (375n — 875)4n +
600^3n +1800n2n +1550)/3600. [For example, V16 = 40454337297; = 10480142147.]
259. (a) The signatures at level l are {Xl+1,... ,Xn } together with all (’n) l-element
subsets of {Y1 , . . . , Yn }. So there are 2n of them; also 2 + ln=0(n — l) nl = n2n-1 + 2
ZDD nodes; and ((n2 + 3n + 4)2n — 4)/4 updates.
(b) Now the signatures are {Xl+1,... , Xn} plus l-element subsets of {Y1,... ,Y;+1}.
So we get n2 + 1 cache memos; n2 + 2 ZDD nodes; (2n3 + 15n2 + n)/6 updates.
260. The menage problem, with ~ n!/e2 solutions, leads to unexpected running times:
We seem to get roughly order n3/2pn updates, where p ~ 3.1; but better results are
obtained for n > 13 when the MRV heuristic is not used in step Z3! Then the running
time may well be 0(nen), although the ZDD size apparently grows as npn with p ~ 2.56.
The other problem, with Ln + 2 solutions, needs just 6n + 9 memos, 8n — 9 ZDD
nodes, and 34n — 58 updates.
July 26, 2019
186 ANSWERS TO EXERCISES 7.2.2.1
261. (a) Introduce primary items v- and v+ for each vertex v, representing the factors
possibility of passing through v; but omit v- for v € S, and v+ for v € T. Also plane partitions
totally symmetric
introduce secondary items v, whose color (if nonzero) represents the path number. The Beluhov
main options are ‘u+ v- u:k v:k’, for each arc u —>v and for 1 < k < m. There also preprocessing
Rowwise ordering
are options ‘v- v:0’ for all v €/ S, and ‘v+ v:0’ for all v €/ T. columnwise ordering
Moreover, we need a way to number each path canonically, so that we don’t get MRV heuristic
m! equivalent solutions. (The method of exercise 122 does not work with Algorithm Z.) Aztec diamond
arctic circle
If S = {s1 , . . . , sp}, introduce primary items xk and secondary items yk for 1 < k < p, Jockusch
with the following options: ‘xk sk:0 yk-1:j yk:j’ and ‘xk sk:(j+1) yk-1:j yk:(j+1)’, for Propp
1 < k < p and 0 < j < k. [Omit the item yk-1:j when k = 1; omit options with yp = m.] Shor
Cohn
Many of these options can never be used. Algorithm P readily removes them. Elkies
(b) Remove unreachable vertices and unreachable arcs from G, if necessary, so Propp
Grensing
that the only sources and sinks are S = {s1, . . . , sk} and T = {t1, . . . , tk}. Then use Carlsen
items v- , v+ , v and the main options of the construction in part (a); but omit any Zapp
Ciucu
option that specifies sj :k or tj:k for j = k.
(c) This is a trick question, because each path contains exactly one vertex on
the diagonal. The problem therefore factors neatly into two independent subproblems.
It suffices to find n - 1 vertex-disjoint paths from S = {(0, 1), . . . , (0, n-1), (1, n), . . . ,
(n-1, n)} to T = {(1, 1), . . . , (n-1, n-1)} in the digraph with vertices (i, j) for 0 <
i < j < n, (i,j) / {(0, 0), (0,n), (n,n)}, and arcs (i, j) —* (i + 1, j), (i,j) —* (i,j - 1).
If this problem has Pn solutions, given by a ZDD Z with Mn nodes, the original
problem has /',) solutions, given by a ZDD Z" with 2Mn nodes. We obtain Z" by
replacing T in Z with the root of Z', where Z specifies the reflections of the paths of Z.
Algorithm Z needs just 7 gigamems to find P16 = 992340657705109416 and M16 =
3803972. (In fact, Pn is known to be П 1<i<j<k<n(i+j' + k — 1)/(i+j+k — 2), the number
of plane partitions that are totally symmetric: N. Beluhov [to appear] has found a nice
way to glue six triangular diagrams together, in kaleidoscope fashion, which establishes
a one-to-one correspondence linking these paths to symmetrical diamond tilings like
those of exercise 262(b).)
(d) There are exactly 47356 solutions. Algorithm C finds them in 278 G/, without
preprocessing; but it needs only 760 M/, after Algorithm P has removed redundant
options. Algorithm Z, by contrast, handles the problem in 92 G/, using 7 gigabytes
of memo-cache memory (without preprocessing); 940 M/ and 90 megabytes (with).
Hence Algorithm Z is undesirable for problem (d), but essential for problem (c).
262. (a) The ordering of the primary items — the cells of Sn —is critical: Rowwise
ordering (left-to-right, top-to-bottom) causes exponential growth; but columnwise or
dering (top-to-bottom, left-to-right) yields linear ZDD size, and 0(n2) running time.
Furthermore, it turns out to be better not to use the MRV heuristic, when n > 18.
Then the number of ZDD nodes is 154440n — 2655855 for all n > 30. Only 2.2 G/ are
needed for n = 32. There are 68719476736 = ( 2 )72 solutions for S16 , via exercise
7.1.4-208; for S32 there are 152326556015596771390830202722034115329 w 1.552200.
(An Aztec diamond of order m has exactly 2m(m+1)/2 domino tilings; moreover, as
m ^ to, the dominoes at the corners are q.s. aligned, except within an “arctic circle” of
radius m/ 2. See W. Jockusch, J. Propp, and P. Shor, arXiv:math/9801068 [math.CO]
(1995), 44 pages; H. Cohn, N. Elkies, and J. Propp, Duke Math. J. 85 (1996), 117-166.
See also D. Grensing, I. Carlsen, and H.-Chr. Zapp, Philos. Mag. A41 (1980), 777-781.)
[Tilings of the more general shapes Smn considered here, where we replace 16 by
2m and 7 by m—1, are more mysterious. M. Ciucu observes that R(2m)(n-2m) C Smn C
R(2m)(n+2m), where Rkn is a k X n rectangle; furthermore both R(nm)(n+nm) \ Smn and Stanley
Smn \ R(2m)(n-2m) are tilable. Richard Stanley has shown, in Discrete Applied Math. vertex-disjoint paths
Randall
12 (1985), 81-87, that R(2m)n has ~ a2m^nm1 tilings, for fixed m as n ^ to, where convex triangular regions
plane partitions
(1+V2)k+1 - (1-72)k+1 f o t ---------- —A n jn Klarner
ak = --------------- 2^2--------------- , M2m = cos Qj + V1+cos2 j , Qj = 2m+1 . reverse plane partition
Cohn
Larsen
Hence Smn has ©(^nm) tilings in that limit. But if m = an as n ^ to, the limiting Propp
“arctic curve” outside which dominoes tend to be frozen remains to be discovered.] ellipse
There is, incidentally, a beautiful connection between domino tilings and vertex- Boutillier
(b) In this case the triangle coordinates of answer 124 yield linear growth if we
use items (x, y) for 0 < x < n + 8, 0 < y < 16, x + y > 8; (x, y)' for 0 < x < n + 8,
0 < У < 16, 7 < x + y < n + 15. The options are ‘(x,y) (x/,y/)’, where (x',y') =
(x, y) - {(0, 0), (0, 1), (1, 0)} and both items exist. Then the ZDD size (without MRV)
turns out to be 257400n - 1210061, for all n > 7.
The convex triangular regions that can be tiled with diamonds are precisely those
that have equally many Д and V triangles, namely the generalized hexagons Tlmn
with sides (l, m, n, l, m, n) for some l, m, n > 0. These tilings are equivalent to plane
partitions that fit in an l X m X n box. In fact you can “see” this equivalence, because
the diagrams resemble cubies packed into a corner of the box! (David Klarner made
this discovery in the 1970s, but didn’t publish it.) Therefore every tiling of Tn has
respectively (1, 2, . . . , 8, 7, . . . , 1) vertical diamonds in rows (1, 2, . . . , 15), hence
00012457
64 in all; and these occurrences are nested. For example, the middle diagram 1134569c
12368abc
corresponds to the reverse plane partition shown here. (See exercise 5.1.4-36, 25789bbc
from which it follows that the generalized hexagon Tlmn has exactly П1тп = 4578accc
459aaccc
Hillm=1IIn=1(i+j + k- 1)/(i+j + k- 2) tilings. In particular, we have П888 = 569aaccc
5055160684040254910720; П88(16) = 20657157 889 14012 1 82 6 9 3 9 9 1 725 3 9 0 6 25.) bbbbcccc
[In New York J. of Math. 4 (1998), 137-165, H. Cohn, M. Larsen, and J. Propp
studied random tilings of Tlmn when l, m, and n approach infinity with constant scaling,
and conjectured that they are q.s. “frozen” outside of the largest enclosed ellipse. See
also the more general results of C. Boutillier, Annals of Probability 37 (2009), 107-142.]
263. parameters solutions items options Alg C time, space Alg Z time, space ZDD
(a) organ-pipe order 14772512 32 + 58 256 40 G^ 23 KB 55 G^ 4.1 GB 56M
(b) 6X10 2339 72 + 0 2032 4.1 G/л 230 KB 3.1 G/л 23 MB 11K
(b) 8 X 8, square 16146 77 + 1 2327 20 G^ 264 KB 14 G^ 101 MB 59K
(b) 8 X 8, straight 24600 77 + 1 2358 36 G^ 267 KB 26 G^ 177 MB 93K
(b) 8 X 8, skew 23619 77 + 1 2446 28 G/л 275 KB 20 G/л 137 MB 84K
(b) 8 X 8, ell 60608 77 + 1 2614 68 G^ 291 KB 44 G^ 276 MB 183K
(b) 8 X 8, tee 25943 77 + 1 2446 35 G^ 275 KB 25 G^ 166 MB 92K
(c) aaa placed 987816 49 + 42 1514 25 G/л 149 KB 18 G/л 646 MB 2.2M
July 26, 2019
188 answers to exercises 7.2.2.1
(d) (7, 0, 3) 137216 64 + 128 3970 8.5 Gp 642 KB 1.7 Gp 20 MB 210K stable sorting
(d) (7, 3, 4) 41280 70 + 140 4762 3.2 Gp 769 KB 1.0 Gp 13 MB 122K Nishino
Yasuda
(e) p=6, words(1200) 1 12 + 1230 14400 17 Gp 2 MB 25 Gp 91 MB 14 Minato
(f) kill symmetry 44
* 12 + 36 1188 1.3 Gp 110 KB 0.9 Gp 10 MB 186 Nagata
visible nodes
(g) unmodified 18 1165 + 66 4889 202 Gp 509 MB 234 Gp 8.9 GB 2049 signature
(g) modified 1 1187 + 66 5143 380 Gp 537 MB 424 Gp 15 GB 336 MRV
(g) preprocessed 18 446 + 66 666 223 Mp 66 KB 1.8 Mp 136 KB 574 author
UNIX
* includes solutions that touch all cells extended hexadecimal digits
hexadecimal notation, extended
264. Let the primary items be linearly ordered, and let r(o) be the smallest primary base placements
item in option o. If (o? l: h) is a ZDD node, every option o' in the subZDD rooted at h sorted
has r(o') > r(o), because o covers r(o) and smaller items have already been covered. packed integers
straight tromino
Moreover, if l = 0, the option o' in node l has r(o') = r(o); and o' precedes o in the input.
Thus, if we use a stable sorting algorithm to sort the options by decreasing r(o),
the ZDD will respect the reverse of this ordering. [This result was proved by Nishino,
Yasuda, Minato, and Nagata in their original paper. Unfortunately, the algorithm is
usually too slow without MRV, except in special situations like those of exercise 262.]
265. Every solution below any given ZDD node covers the same primary items. If all
items are primary, no two visible nodes have the same signature. And the nodes of the
chain below every visible node are distinct, because they branch on different options.
Now suppose we have three primary items {p, q, r}, and one secondary item s,
with options ‘p’, ‘p r’, ‘p s’, ‘q r’, ‘q s’. If we don’t use MRV, we’ll branch on p.
Choice 1, ‘p’, leads to a subproblem with signature 0111 that outputs I2 = (q r? 0: 1),
I3 = (p? 0: 2). Choice 2, ‘p r’, leads to a subproblem with signature 0101 that outputs
I4 = (q s? 0: 1), I5 = (pr? 3: 4). Choice 3, ‘p s’, leads to a subproblem with signature
0110 that outputs I6 = (q r? 0: 1), I7 = (p s? 5: 6). And I6 = I2 .
A similar example, with items {q1, q2, q3, r1, r2, r3} in place of {q, r}, and with 23
options ‘p’, ‘p ri’, ‘p s’, ‘qi qj’, ‘ri rj’, ‘qi ri’, ‘qi rj’, ‘qj ri’, ‘qi s’, for 1 < i < j < 3,
fails when MRV dictates the choices.
266. Let the given shape be specified as a set of integer pairs (x, y). These pairs might
simply be listed one by one in the input; but it’s much more convenient to accept a
more compact specification. For example, the utility program with which the author
prepared the examples of this book was designed to accept UNIX-like specifications
such as ‘[14-7]2 5[0-3]’ for the eight pairs {(1, 2), (4, 2), (5, 2), (6, 2), (7, 2), (5, 0),
(5, 1), (5, 3)}. (Notice that a pair is included only once, if it’s specified more than
once.) The range 0 < x, y < 62 has proved to be sufficient in almost all instances, with
such integers encoded as single “extended hexadecimal digits” 0, 1, . . . , 9, a, b, . . . , z,
A, B, ... , Z. The specification ‘ [1-3] [1-k] ’ is one way to define a 3 x 20 rectangle.
Similarly, each of the given polyominoes is specified by stating its piece name and
a set T of typical positions that it might occupy. Such positions (x, y) are specified using
the same conventions that were used for the shape; they needn’t lie within that shape.
The program computes base placements by rotating and/or reflecting the elements
of that set T . The first base placement is the shifted set T0 = T - (xmin, ymin), whose
coordinates are nonnegative and as small as possible. Then it repeatedly applies an
elementary transformation, either (x,y) ^ (y,xmax — x) or (x,y) ^ (y,x), to every
existing base placement, until no further placements arise. (That process becomes easy
when each base placement is represented as a sorted list of packed integers (x -C 16)+ y.)
For example, the typical positions of the straight tromino might be specified as ‘1[1-3]’;
it will have two base placements, {(0, 0), (0, 1), (0, 2)} and {(0, 0), (1, 0), (2, 0)}.
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 189
After digesting the input specifications, the program defines the items of the exact secondary
problem, which are (i) the piece names; (ii) the cells xy of the given shape. break symmetry
author
Finally, it defines the options: For each piece p and for each base placement T' color controls
of p, and for each offset (Sx,Sy) such that T' + (Sx, Sy) lies fully within the given shape, Historical notes
cells versus pieces
there’s an option that names the items {p} U {(x + Sx,y + Sy) | (x,y) 6 Tz}. pieces versus cells
(The output of this program is often edited by hand, to take account of special Soma cube
circumstances. For example, some items may change from primary to secondary; some Peter-Orth
aspects
options may be eliminated in order to break symmetry. The author’s implementation Grunbaum
also allows the specification of secondary items with color controls, along with base Shephard
placements that include such controls.) Mercer
Gardner
Historical notes: Early algorithms for polyomino packing failed to realize the Conway
essentially unity between cells to be covered and pieces to be covered; their treatment secondary item
flipped over
of cells was quite different from their treatment of pieces. The fact that both cells and Scott
pieces are primary items of a “pure” exact cover problem was first noticed in connection break symmetry
with the Soma cube, by C. Peter-Orth [Discrete Mathematics 57 (1985), 105-121]. The Fairbairn
bipair
base placements of tiles that are to be translated (but not rotated or reflected) are called Pestieau
“aspects” in Tilings and Patterns by Griinbaum and Shephard (1987). Bouwkamp
267. RUSTY. [Leigh Mercer posed a similar question to Martin Gardner in 1960.]
268. As in the 3 x 20 example considered in the text, we can set up an exact cover
problem with 12 + 60 items, and with options for every potential placement of each
piece. This gives respectively (52, 292, 232, 240, 232, 120, 146, 120, 120, 30, 232, 120)
options for pieces (O, P, . . . , Z) in Conway’s nomenclature, thus 1936 options in all.
To reduce symmetry, we can insist that the X occurs in the upper left corner; then
it contributes just 10 options instead of 30. But some solutions are still counted twice,
when X is centered in the middle row. To prevent this we can add a secondary item
‘s’: Append ‘s’ to the five options that correspond to those centered appearances; also
append ‘s’ to the 60 options that correspond to placements where the Z is flipped over.
Without those changes, Algorithm X would use 10.04 G^ to find 4040 solutions;
with them, it needs just 2.93 G^ to find 1010.
This approach to symmetry breaking in pentomino problems is due to Dana Scott
[Technical Report No. 1 (Princeton University Dept. of Electrical Engineering, 10 June
1958)]. Another way to break symmetry would be to allow X anywhere, but to restrict
the W to its 30 unrotated placements. That works almost as well: 2.96 G^.
269. There’s a unique way to pack P, Q, R, U, X into a 5 x 5 square, and to pack
the other seven into a 5 x 7. (See below.) With independent reflections, together with
rotation of the square, we obtain 16 of the 1010. There’s also a unique way to pack
P, R, U into a 5 x 3 and the others into a 5 x 9 (noticed by R. A. Fairbairn in 1967),
yielding 8 more. And there’s a unique way to pack O, Q, T, W, Y, Z into a 5 x 6,
plus two ways to pack the others via a bipair, yielding another 16. (These paired 5 x 6
patterns were apparently first noticed by J. Pestieau; see answer 286.) Finally, the
packings in the next exercise give us 264 decomposable 5 x 12s altogether.
[Similarly, C. J. Bouwkamp discovered that S, V, T, Y pack uniquely into a 4 x 5,
while the other eight can be put into an 4 x 10 in five ways, thus accounting for 40 of
the 368 distinct 4 x 15s. See JRM 3 (1970), 125.]
270. Without symmetry reduction, 448 solutions are found in 1.24 G^. But we can flipped Z’s
restrict X to the upper left corner, as in answer 268, flagging its placements with ‘s’ Haselgrove, Colin
Haselgrove, Jenifer
when centered in the middle row or middle column (but not both). Again the ‘s’ is Potts
appended to flipped Z’s. Finally, when X is placed in dead center, we append another Gardner
Golomb
secondary item ‘c’, and append ‘c’ to the 90 rotated placements of W. This yields 112 secondary items
solutions, after 0.35 G^.
Or we could leave X unhindered but curtail W to 1/4 of its placements. That’s
easier to do (although not quite as clever) and it finds those 112 in 0.44 G^.
Incidentally, there aren’t actually any solutions with X in dead center.
271. The exact cover problem analogous to that in exercise 268 has 12 + 60 items
and (56, 304, 248, 256, 248, 128, 1152, 128, 128, 32, 248, 128) options. It finds 9356
solutions after 16.42 G^ of computation, without symmetry reduction. But if we insist
that X be centered in the upper left quarter, by removing all but 8 of its placements,
we get 2339 solutions after just 4.11 G^. (The alternative of restricting W’s rotations
is not as effective in this case: 5.56 G^.) These solutions were first enumerated by
C. B. and Jenifer Haselgrove [Eureka: The Archimedeans’ Journal 23 (1960), 16-18].
272. (a) Obviously only k = 5 is feasible. All such packings can be obtained by
omitting all options of the cover problem that straddle the “cut.” That leaves 1507 of
the original 2032 options, and yields 16 solutions after 104 M^. (Those 16 boil down
to just the two 5 x 6 decompositions that we already saw in answer 269.)
(b) Now we remove the 763 options for placements that don’t touch the boundary,
and obtain just the two solutions below, after 100 M^. (This result was first noticed
by Tony Potts, who posted it to Martin Gardner on 9 February 1960.)
(c) With 1237 placements/options, the unique solution is now found after 83 M^.
(d) There are respectively (0, 9, 3, 47, 16, 8, 3, 1, 30, 22, 5, 11) solutions for
pentominoes (O, P, Q, . . . , Z). (The I/O pentomino can be “framed” by the others in
11 ways; but all of those packings also have at least one other interior pentomino.)
(e) Despite many ways to cover all boundary cells with just seven pentominoes,
none of them lead to an overall solution. Thus the minimum is eight; 207 of the 2339
solutions attain it. To find them we might as well generate and examine all 2339.
(f) The question is ambiguous: If we’re willing to allow the X to touch unnamed
pieces at a corner, but not at an edge, there are 25 solutions (8 of which happen to
be answers to part (a)). In each of these solutions, X also touches the outer boundary.
(The cover and frontispiece of Clarke’s book show a packing in which X doesn’t touch
the boundary, but it doesn’t solve this problem: Using Golomb’s piece names, there’s
an edge where X meets I, and there’s a point where X meets P.) There also are two
packings in which the edges of X touch only F, N, U, and the boundary, but not V.
On the other hand, there are just 6 solutions if we allow only F, N, U, V to touch
X’s corner points. One of them, shown below, has X touching the short side and seems
to match the quotation best. These 6 solutions can be found in just 47 M^, by intro
ducing 60 secondary items as sort of an “upper level” to the board: All placements of X
occupy the normal five lower-level cells, plus up to 16 upper-level cells that touch them;
all placements of F, N, U, V are unchanged; all placements of the other seven pieces
occupy both the lower and the upper level. This nicely forbids them from touching X.
273. (a) We could set this up as twelve separate exact cover problems, one for each pen- symmetry
tomino omitted. But it’s more interesting to consider all cases simultaneously, by giving nonsharp preference heuristic
flipped
a “free pass” to one pentomino as follows: Add a new primary item ‘#’, and twelve new Dudeney
options ‘# O’, ‘# P’, . . . , ‘# Z’. The sixty items ij are demoted to secondary status. checkered
parity
To remove symmetry, delete 3/4 of the options for piece V; also make its new one-sided pentominoes
option ‘# V s’, and add ‘s’ to 3/4 of the options for piece W, where ‘s’ is a new secondary historical notes
item. That makes a total of 1194 options, involving 13 + 61 items. Reid
Catel
If Algorithm X branches first on #, the effect is equivalent to 12 separate runs;
the search tree has 7.9 billion nodes, and the run time is 16.8 teramems. But if we use
the nonsharp preference heuristic (see answer 10), the algorithm is able to save some
time by making decisions that are common to several subcases. Its search tree then
has 7.3 billion nodes, and the run time is 15.1 teramems. Of course both methods give
the same answer, which is huge: 118,034,464.
(b) Now keep items ij primary, but introduce 60 new secondary items ij'. There
are 60 new options ‘ij ij' (i+1)jz i(j+1)' (i+1)(j+1)/’, where we omit items containing
(i+1) when i = 2 or (j+1) when j = 19. This problem has 1254 options involving 73+61
items. Its search tree (with deprecated # branching) has about 950 million nodes; it
finds 4,527,002 solutions, after about 1.5 teramems of computation.
A related, but much simpler, problem asks for packings in which exactly one hole
appears in each of the column pairs {1, 2}, {5, 6}, {9, a}, {d, e}, {h, i}. That one has
1224 options, 78+1 items, 20 meganodes, 73 gigamems, and 23642 solutions. Here’s one:
(c) A setup like the one in (a) yields 1127 options, 13+ 58 items, 1130 meganodes,
2683 gigamems, 22237 solutions. (One of the noteworthy solutions is illustrated above.)
274. Restrict X to five essentially different positions; if X is on the diagonal, also keep
Z unflipped by using the secondary item ‘s’ as in answer 268. There are respectively
(16146, 24600, 23619, 60608, 25943) solutions, found in (20.3, 36.3, 28.0, 68.3, 35.2) Од.
In each case the tetromino can be placed anywhere that doesn’t immediately cut off
a region of one or two squares. [The twelve pentominoes first appeared in print when
H. E. Dudeney published The Canterbury Puzzles in 1907. His puzzle #74, “The
Broken Chessboard,” presented the first solution shown above, with pieces checkered
in black and white. That parity restriction, with the further condition that no piece is
turned over, would reduce the number of solutions to only 4, findable in 120 Мд.]
The 60-element subsets of the chessboard that can’t be packed with the pentomi-
noes have been characterized by M. Reid in JRM 26 (1994), 153-154.
The earliest known polyomino puzzle appeared in P. F. Catel’s VerzeichniB von
sammtlichen Waaren (Berlin, 1785), #11: 4 Z pentominoes + 4 ells make a 6x 6 square.
July 26, 2019
192 answers to exercises 7.2.2.1
275. Yes, in seven essentially different ways. To remove symmetry, we can make symmetry
the O vertical and put the X in the right half. (The pentominoes will have a total Griinbaum
Shephard
of 6 X 2+5 X 3 + 4 = 31 black squares; therefore the tetromino must be ^j-1.) torus
torus, generalized
276. These shapes can’t be packed in a rectangle. But we can use the “supertile” [щй] Sicherman
to make an infinite strip • • • • • •. [See B. Griinbaum and G. C. Shephard, wallpaper
Tilings and Patterns (1987), 508.] We can also tile the plane with a supertile like iS^T, tatami
SAT
or even use a generalized torus such as . (see exercise 7-137). That supertile was directed acyclic graph
used in 2009 by George Sicherman to make tetromino wallpaper. source vertices
sink vertices
277. The 2339 solutions contain 563 that satisfy the “tatami” condition: No four pieces isolated vertices
meet at any one point. Each of those 563 leads to a simple 12-vertex graph coloring Hansson
problem; for example, the SAT methods of Section 7.2.2.2 typically need at most two symmetries
278. The 2339 solutions in answer 271 restrict X to the upper left quarter; we must
be careful not to include bipairs that might swap X out of that region. One way (see
exercise 212) is to order the items: Put X first, then the other piece names, then the
place names from 00 to 59. All swaps involving X will then move it up or left.
The 34 bipairs of the catalog now result in an exact cover problem with the same
primary items and options as before, but with 2804 new secondary items. They limit
the number of solutions to 1523; but the running time increases to 4.26 G^.
[The proof idea of Theorem S yields an interesting directed acyclic graph with
2339 vertices and 937 arcs. It has 1528 source vertices, 1523 sink vertices, and 939
isolated vertices (both sources and sinks). If we ignore the arc directions, there are
1499 components, of which the largest has size 10. That component contains the
leftmost solution below, which belongs to four different bipairs. There also are two com-
ponents of size 8, with three nonoverlapping bipairs. The rightmost solution belongs to
a component of size 6, which would grow to size 8 if X were allowed to move downward.]
This exact cover problem has 850 solutions, 502 of which are faultfree. Here’s three-colorable
one of the 29 strongly three-colorable ones, shown before and after its ends are joined: flipped
secondary item
Gardner
Hawkins
bottom: Lindon
Fuhlendorf
281. Both shapes have 8-fold symmetry, so we can save a factor of nearly 8 by placing
the X in (say) the north-northwest octant. If X thereby falls on the diagonal, or in
the middle column, we can insist that the Z is not flipped, by introducing a secondary
item ‘s’ as in answer 270. Furthermore, if X occurs in dead center — this is possible
only for shape (i) — we use ‘c’ as in that answer to prohibit also any rotation of the W.
Thus we find (a) 10 packings, in 3.5 G^; (b) 7302 packings, in 353 G^; for instance
It turns out that the monomino must appear in or next to a corner, as shown. [The
first solution to shape (i) with monomino in the corner was sent to Martin Gardner
by H. Hawkins in 1958. The first solution of the other type was published by J. A.
Lindon in Recreational Mathematics Magazine #6 (December 1961), 22. Shape (ii)
was introduced and solved much earlier, by G. Fuhlendorf in The Problemist: Fairy
Chess Supplement 2, 17 and 18 (April and June, 1936), problem 2410.]
282. It’s easy to set up an exact cover problem in which the cells touching the poly-
omino are primary items, while other cells are secondary, and with options restricted
to placements that contain at least one primary item. Postprocessing can then remove
spurious solutions that contain holes. Typical answers for (a) are
representing respectively (9, 2153, 37, 2, 17, 28, 18, 10, 9, 2, 4, 1) cases. For (b) they’re
representing (16, 642, 1, 469, 551, 18, 24, 6, 4, 2, 162, 1). The total number of fences
is respectively (3120, 1015033, 8660380, 284697, 1623023, 486, 150, 2914, 15707, 2,
456676, 2074), after weeding out respectively (0, 0, 16387236, 398495, 2503512, 665,
600, 11456, 0, 0, 449139, 5379) cases with holes. (See MAA Focus 36, 3 (June/July
July 26, 2019
194 ANSWERS TO EXERCISES 7.2.2.1
2016), 26; 36, 4 (August/September 2016), 33.) Of course we can also make fences for second death
one shape by using other shapes; for example, there’s a beautiful way to fence a Z with Gardner
pentominoes, shortest games
12 Ps, also a unique way to fence one pentomino with only three copies of another. benchmarks
283. The small fences of answer 282(a) already meet this condition — except for the Haselgrove
Wassermann
X, which has no tatami fence. The large fences for T and U in 365(b) are also good. Ostergard
But the other nine fences can no longer be as large: Meeus
180 rotation
central symmetry, see 180^ rotation
Patent
Pestieau
[The tatami condition can be incorporated into the exact cover problem by intro
ducing a secondary item /ij for each interior point ij. Add this item to every placement
option that has a convex corner at ij and occupies either the cell to the northeast or
the cell to the southwest. However, for this exercise it’s best simply to apply the tatami
condition directly to each ordinary solution, before postprocessing for hole-removal.]
284. This problem is readily solved with the “second death” algorithm of exer
cise 19, by letting the four designated piece names be the only primary items.
The answers to both (a) and (b) are unique. [See M. Gardner, Scientific Amer
ican 213,4 (October 1965), 96-102, for Golomb’s conjectures about minimum
blocking configurations on larger boards.]
285. This exercise, with 3 x 30, 5 x 18, 6 x 15, and 9 x 10 rectangles, yields four
increasingly difficult benchmarks for the exact cover problem, having respectively (46,
686628, 2567183, 10440433) solutions. Symmetry can be broken as in answer 270. The
3 x 30 case was first resolved by J. Haselgrove; the 9 x 10 packings were first enumerated
by A. Wassermann and P. Ostergard, independently. [See New Scientist 12 (1962), 260
261; J. Meeus, JRM 6 (1973), 215-220; and FGbook pages 455, 468-469.] Algorithm X
needs (.006, 5.234, 15.576, 63.386) teramems to find them.
286. Two solutions are now equivalent only when related by 180 rotation. Thus there
[In U.S. Patent 2900190 (1959, filed 1956), J. Pestieau remarked that these 64 problems
would give his pentomino puzzle “unlimited life and utility.”]
287. Let c = (12, 11, . . . , 1) for pieces (O, P, . . . , Z) when assigning costs to each option.
Algorithm X$, when told that every option contains one piece and five cells, finds
in respectively (1.5, 3.4, 3.3, 2.9, 3.2, 1.4, 1.1) G^. The corresponding times for Algo symmetry
rithm X are (3.7, 10.0, 16.4, 16.4, 10.0, 3.7, 2.0) G^. (However, we could reduce factors
min-cost solutions
symmetry when applying Algorithm X, then calculate the values of four or eight differ max-cost sols
ent reflections or rotations whenever a solution is found; that would often be faster.) Guy
Gillen
288. When symmetry is removed efficiently, Algorithm X needs 63 T^ to visit all of the black cells
essentially different solutions. But Algorithm X$ wins this competition, by discovering checkering
parity
(which both are uniquely optimum) in 28.9 Tu and 25.1 T^, respectively.
289. (a) One of the 8-2422-85-263• 95• 224^262• 226^ 228• 96• 105-174 solutions is shown
in Fig. A-3. (It isn’t hard to keep pentominoes of the same shape from touching.)
(b) Now there are 1472 • 5915 • 596 • 251 • 542 • 204 • 170 • 226 • 228 • 96 • 651 • 316.
(c) The first seven columns left of the middle line can yield six 12-cell regions only
by using all 72 cells. Thus the problem factors neatly into ten independent problems of
the form (i). That problem has 7712 solutions with six connected regions; Algorithm X$
needs a search tree of only 622 nodes to determine that there are just 11 minimum
perimeter solutions. Three of them are symmetrical; and the nicest is shown in (ii).
(And two of the solutions, such as (iii), maximize the total perimeter.)
Unfortunately (36) can’t be expanded into the desired 720-cell shape based on (ii),
because the scaled-up Q can’t be packed. But the alternative form of (36) does lead to
16 • 2139 • 6 • 97 • 259 • 111 • 44 • 64 • 79 • 12 • 17 • 111 solutions, such as the one in Fig. A-3.
290. There are no ways to fill 2 x 20; 66 • 4 ways to fill 4 x 10;
84 • 4 ways to fill 5 x 8. None of the solutions are symmetrical.
[See R. K. Guy, Nabla 7 (1960), 99-101.]
291. The puzzles for January, April, September, and December (say) are equivalent;
thus only 4^31 = 124 puzzles need to be solvable, not 366. Only 53 of the 220 pentomino
triples are unsuitable: First reject all 55 that include X, and all 10 that are subsets
of {O, R, S, W, Z}; then restore P{O, Q, S, T, U, V, Y}X and ORS, OSW, RSW; then
reject RTZ and TWZ. Of the remaining 167 triples, PQV is by far the easiest: Every
PQV puzzle has at least 1778 solutions! The hardest is QTX, which allows only about
33 solutions per day, on average. [This puzzle was designed by Marcel Gillen, © 2018,
who made it with pentominoes R, U, W for the 2018 International Puzzle Party.]
292. Most of the hexominoes will have three black cells and three white cells, in any
“checkering” of the board. However, eleven of them (shown as darker gray in the
illustration) will have a two-to-four split. Thus the total number of black cells will
always be an even number between 94 and 116, inclusive. But a 210-cell rectangle
July 26, 2019
196 ANSWERS TO EXERCISES 7.2.2.1
parity
exact cover
factoring
bipair of hexominoes
always contains exactly 105 black cells. [See The Problemist: Fairy Chess Supplement
2,9-10 (1934-1935), 92, 104-105; Fairy Chess Review 3,4-5 (1937), problem 2622.]
Benjamin’s triangular shape, on the other hand, has 1+3+5+^ • -+19 = 102 = 100
cells of one parity and 221 - 102 = 110 of the other. It can be packed with the 35
hexominoes in a huge number of ways, probably not feasible to count exactly.
293. The parity considerations in answer 292 tell us that this is possible only for the
“unbalanced” hexominoes, such as the one shown. And in fact, Algorithm X readily
finds solutions for all eleven of those, too numerous to count. Here’s an example:
[See Fairy Chess Review 6 (April 1947) through 7 (June 1949), problems 7252, 7326,
7388, 7460, 7592, 7728, 7794, 7865, 7940, 7995, 8080. See also the similar problem 7092.]
294. Each castle must contain an odd number of the eleven unbalanced hexominoes
(see answer 292). Thus we can begin by finding all sets of seven hexominoes that can
be packed into a castle: This amounts to solving 11 11
1 + 3 + 5 + 7
11 11 = 968 exact
cover problems, one for each potential choice of unbalanced elements. Each of those
problems is fairly easy; the 24 balanced hexominoes provide secondary items, while the
castle cells and the chosen unbalanced elements are primary. In this way we obtain
39411 suitable sets of seven hexominoes, with only a moderate amount of computation.
That gives us another exact cover problem, having 35 items and 39411 options.
This secondary problem turns out to have exactly 1201 solutions (found in just 115 G^),
each of which leads to at least one of the desired overall packings. Here’s one:
In this example, two of the hexominoes in the rightmost castle can be flipped vertically;
and of course the entire contents of each castle can independently be flipped horizon
tally. Thus we get 64 packings from this particular partition of the hexominoes (or
July 26, 2019
7.2.2.1 answers to exercises 197
maybe 64 • 5!, by permuting the castles), but only two of them are “really” distinct. Hansson
Taking multiplicities into account, there are 1803 “really” distinct packings altogether. Povah
Hansson
[Frans Hansson found the first way to pack the hexominoes into five equal shapes, Sicherman
using pp as the container; see Fairy Chess Review 8 (1952-1953), problem 9442. His strongly three-colorable
dynamic programming
container admits 123189 suitable sets of seven, and 9298602 partitions into five suitable trominoes
sets instead of only 1201. Even more packings are possible with the container ^, van de Wetering
which has 202289 suitable sets and 3767481163 partitions!]
In 1965, M. J. Povah packed all of the hexominoes into containers of shape L~|,
using seven sets of five; see The Games and Puzzles Journal 2 (1996), 206.
295. By exercise 292, m must be odd, and less than 35. F. Hansson posed this question
in Fairy Chess Review 7 (1950), problem 8556. He gave a solution for m = 19,
and claimed without proof that 19 is maximum. The 13 dark gray hexominoes in this
diagram cannot be placed in either “arm”; so they must go in the center. (Medium gray
indicates pieces that have parity restrictions in the arms.) Thus we cannot have m > 25.
When m = 23, there are 39 ways to place all of the hard hexominoes, such as
However, none of these is completable with the other 22; hence m < 21.
When m = 21, the hard hexominoes can be placed in 791792 ways, without
creating a region whose size isn’t a multiple of 6 and without creating more than one
region that matches a particular hexomino. Those 791792 ways have 69507 essentially
distinct “footprints” of occupied cells, and the vast majority of those footprints appear
to be impossible to fill. But in 2016, George Sicherman found the remarkable packing
which not only solves m = 21, it yields solutions for m = 19, 17, 15, 11, 9, 7, 5, and 3 by
simple modifications. Sicherman also found separate solutions for m = 13 and m = 1.
296. Stead’s original solution makes a very pleasant three-colored design:
[See Fairy Chess Review 9 (1954), 2-4; also FGbook, pages 659-662.]
This problem is best solved via the techniques of dynamic programming (Sec
tion 7.7), not with Algorithm X, because numerous subproblems are equivalent.
297. Yes — in fact, there are so many ways, further conditions ought to be imposed.
Torbijn’s original quest, to leave a hexomino-shaped “hole” in one square, turns out to
have been impossible. But there’s a nice alternative: We can add the two trominoes.
A. van de Wetering showed in 1991 that exactly 13710 sets of six hexominoes can
fit into a single square. [See JRM 23 (1991), 304-305.] Similarly, exactly 34527 sets of
five hexominoes will fit, when supplemented by two trominoes that both occupy two
July 26, 2019
198 ANSWERS TO EXERCISES 7.2.2.1
black cells. So we’re left with a secondary covering problem, with 35 primary items black cells
and 48237 options, as in answer 294. That problem has 163 solutions (found in 3Тд). parity
monomino
Another alternative, also suggested by van de Wetering, is to place six empty pentominoes
cells symmetrically. He also was able to add a monomino and one of the pentominoes: Benjamin
Keller
The secondary covering problems associated with pentominoes (O, P, . . . , Z) turn out Torbijn
to have (94, 475, 1099, 0, 0, 2, 181, 522, 0, 0, 183, 0) solutions. Torbijn
Meeus
Esser
multiplicity
van de Wetering
symmetrical
298. Make options for the pentominoes in cells xy for 0 < x < 8, 0 < y < 10 as in
exercise 266, and also for the tetrominoes in cells xy for 1 < x < 7, 1 < y < 9. In the
latter options include also items xy':0 for all cells xy in the tetromino, as well as xy':1
for all other cells xy touching the tetromino, where the items xy' for 0 < x < 8 and
0 < y < 10 are secondary. We can also assume that the center of the X pentomino lies
in the upper left corner. There are 168 solutions, found after 1.5 Tp. of computation.
(Another way to keep the tetrominoes from touching would be to introduce secondary
items for the vertices of the grid. Such items are more difficult to implement, however,
because they behave differently under the rotations of answer 266.)
[Many problems that involve placing the tetrominoes and pentominoes together
in a rectangle were explored by H. D. Benjamin and others in the Fairy Chess Review,
beginning already with its predecessor The Problemist: Fairy Chess Supplement (1936),
problem 2171. But this question seems to be new; it was inspired by Michael Keller’s
15 x 18 pentomino + hexomino construction in World Game Review 9 (1989), 3. See
also P. Torbijn’s elegant 13 x 23 packing of all the n-ominoes for 1 < n < 6, in Cubism
For Fun 25, part 1 (1990), 11.]
299. P. J. Torbijn and J. Meeus [JRM 32 (2003), 78-79] have exhibited solutions for
rectangles of sizes 6 x 45, 9 x 30, 10 x 27, and 15 x 18; thus intuition suggests that
enormously many solutions ought to be possible for this case too. But Peter Esser has
surprisingly proved that no packing of the 35 hexominoes into a 5 x 54 rectangle will
occupy all 114 of the border cells. Indeed, the pieces can individually occupy at most
(6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 5+x24, 4+x25, 4+x26,
4+x27, 3+x28, 3+x29, 3+x30, 2+x31, 2+x32, 4+2x33, 3 + 2x34, 3+2x35) border cells,
respectively, under an appropriate numbering of the pieces, where xk = 1 only if piece k
is in a corner. Since there are only four corners, we can occupy at most 6+5+^ • ^+4+3+
3 + (1 + 2 + 2 + 2) = 114 border cells — but only if x33 = x34 = x35 = 1. Unfortunately,
those last three pieces (namely [p, |p p) can’t simultaneously occupy corners.
300. Make options as usual (exercise 266), but also include 100 new options ‘xy Rx
Cy’ for 0 < x, y < 10. Then use Algorithm M, assigning multiplicity 4 to each Rx and
Cy . Remove symmetry by confining X to the upper left corner, and by insisting that
O be horizontal. (a) One of the 31 solutions (found in 12 Gp is shown below. (b)
This case has 5347 solutions (found in 4.6 T^); and if we insist on filling also all cells
just above the diagonals, the solution turns out to be unique (see below). (c) Instead
of focusing on diagonals, Aad van de Wetering noticed that we can require the empty
spaces to be symmetrical. For example, there are 1094 solutions (found in 19.2 Tp
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 199
whose empty spaces are diagonally symmetric. Three of them, like the one shown here, centrally symmetric
are also rather close (92%) to being centrally symmetric (that is, under 180° rotation). quadrants
van de Wetering
shadow
nonsharp heuristic
Thoen
Friedman
multiplicities
Symmetry under reflection
conflict graph
Three others, like the fourth example above, leave a 4 x 4 hole in the corner. Moreover, color that graph
clique
there are 98 solutions (found in 3.2 Tu) whose empty spaces have 100% central sym SAT solver
metry. One of them has a large “moat” between two blocks of pentominoes; another
has connected pentominoes, with holes of size at least 6.
Furthermore, van de Wetering reported that he had found “by accident” a solution
where each of the four 5 x 5 quadrants of the 10 x 10 contained exactly three pentom-
inoes. This additional stipulation is, indeed, easy to add to our MCC formulation: We
omit options that cross quadrant boundaries, append a new item Qt to each option in
the tth quadrant, and give multiplicity 3 to each Qt . It turns out that there actually
are 1,124,352 inequivalent solutions(!), found by Algorithm M in 23 Tu.
But van de Wetering also discovered a class of solutions that’s even more inter
esting: He packed the empty spaces entirely with “shadow” pentominoes, all different!
0 < x,y < 10, as well as O, P, ... , Z; use secondary items xy as well as O', Pz, ... , Zz.
Items #Rx and #Cy have multiplicity 4. Specify two options for each pentomino place
ment, such as ‘V !00 00:1 !01 01:1 !02 02:1 !10 10:1 !20 20:1’ for V in the corner and ‘V'
!00 00:0 !01 01:0 !02 02:0 !10 10:0 !20 20:0’ for its shadow in that place. Also specify 200
further options, ‘#xy #Rx #Cy xy:0’ and ‘#xy xy:1’, for 0 < x,y < 10. Algorithm M
with the nonsharp heuristic will then make intelligent choices. There are (amazingly)
357 solutions, found in 322 teramems with a search tree of 32 giganodes. The first
solution above is one of six that cover exactly six cells of each main diagonal, answering a
question that had been posed by Aad Thoen. The second solution is one of two for which
all seven of the “unambiguously named pentominoes” T, U, V, W, X, Y, Z are among
the shadows. The third solution is one of two that respects 5 x 5 quadrants. [Note:
A similar question, but with identical polyominoes, was Erich Friedman’s “problem of
the month” in May 2007; see www2.stetson.edu/~efriedma/mathmagic/0507.html.]
301. (a) Algorithm M produces 4 • 13330 solutions when we specify the desired multi
plicities for cell items. Symmetry under reflection can be removed by restricting, say,
W to only 1/4 of its options.
(b) Consider the conflict graph on vertices O, P, . . . , Z, defined by declaring pieces
to be adjacent when they appear in the same cell. We can achieve < d levels if and
only if we can color that graph with < d colors. The conflict graph for the given
arrangement has the 4-clique {Q, X, Y, Z}; so it can’t be 3-colored.
(c, d) A SAT solver such as Algorithm 7.2.2.2D quickly determines that exactly
(587, 12550, 193) of the conflict graphs for the 13330 distinct solutions to (a) have
July 26, 2019
200 ANSWERS TO EXERCISES 7.2.2.1
chromatic numbers (3, 4, 5). The first example below can be (uniquely) 3-colored Timmermans
O vy Z | P rwx | Q S tu; the second example has the clique {Q, R, S, W, Y}. nested parentheses
forest
continued fraction
OU XY UW WZ SZ QY QR TU TX TU Bessel functions, gen’lized
OUX UXY UXY SWZ SVW RSY QRY RUX UTX UVX
OT XY RZ SZ VW SY QW RW TX VZ
ORT RTY RTV PSV PQV SWY QSW PVZ PVZ PVZ
OT QR PQ PQ PQ OW OS OZ OP OP
302. (a) There are 94. (But 16 of them have interior “holes” and can’t be used in (b).)
(b) The two solutions are related by rotating four of the pieces:
3 1 4 .
.. 1 5 9 2 6 . .
.. 5
. 3 .
1 5 8 9
.. 7 . . . 9 3 2
.. 3 8 . .
.. . 4 . . . . 6
2 . . . . 6 . . 4
(c) Sixteen different jigsaw sudoku diagrams can be used. The first of them collab
orates with n as shown above; the others probably do too. [Appendix E has the answer.
This exercise was suggested by E. Timmermans, Cubism For Fun 85 (2011), 4-9.]
303. (a) Represent the tree as a sequence a0a1 . . . a2n+1 of nested parentheses; then
a1 . . . a2n will represent the corresponding root-deleted forest, as in Algorithm 7.2.1.6P.
The left boundary of the corresponding parallomino is obtained by mapping each ‘(’
into N or E, according as it is immediately followed by ‘(’ or ‘)’. The right boundary,
similarly, maps each ‘)’ into N or E according as it is immediately preceded by ‘)’ or
‘(’. For example, the parallomino for forest 7.2.1.6-(2) is shown below with part (d).
(b) This series wxy + w2 (xy2 + x2y) + w3(xy3 + 2x2y2 + x3y) + • • • can be
written wxyH (w, wx, wy), where H(w, x, y) = 1/(1 - x - y - G(w, x, y)) generates
a sequence of “atoms” corresponding to places x, y , G where the juxtaposed boundary
paths have the respective forms E , N, or NE inner E
EN N . The area is thereby computed by
diagonals between corresponding boundary points. (In the example from (a), the area is
1+1+1+1+2+2+2+2+2+2+2+2+2+1+1; there’s an “outer” G, whose H is xyxyGy ,
and an “inner” G, whose H is xyyxyxxyy.) Thus we can write G as a continued fraction,
z(C(z) — 1), where C(z) = (1 — ^/1—4z)/(2z) generates the Catalan numbers. Partial Catalan numbers
tatami
derivatives d/dw and d/dz then give Gz(1, z) = z2/(1—4z) and G/(1, z) = 1Д/1—4z — 1. strongly three-colorable
(d) This problem has four symmetries, because we can reflect about either di secondary items
agonal. When n = 5, Algorithm X finds 801 x 4 solutions, of which 129 x 4 satisfy geek art
Levine
the tatami condition, and 16 x 4 are strongly three-colorable. (The tatami condition is Klarner
easily enforced via secondary items in this case, because we need only stipulate that the Rivest
upper right corner of one parallomino doesn’t match the lower left corner of another.) Bender
Goulden
When n = 6 there are oodles and oodles of solutions. All of the trees/parallominoes Jackson
thereby appear together in an attractive compact pattern. Delest
Viennot
Woan
Shapiro
Rogers
Flajolet
Sedgewick
Demaine
Demaine
even/odd coordinates
base placements
(b) Algorithm X quickly finds 501484 = 4 • 2 + 125369 • 4 solutions, including four Nonsharp branching
classes that are symmetric under reflection and 125369 unsymmetric classes. One of multiplicity
the symmetric examples is shown below; also one of the 164 asymmetric classes whose
small squares do at least form a symmetric shape.
(c) The 288 = 4 • 2 + 70 • 4 solutions include four symmetric classes (like the one
shown) and 70 that have no symmetry.
(d) We can set this up as a 7 x 7 problem in which the small squares form a
rectangle whose corners are {47, 74, 8b, b8}. It has 2696 • 2 solutions, all asymmetric;
95 • 2 of them fit in a 5 x 5 box, and 3 • 2 of them have large squares that form the
symmetric shape shown. (e) Now there are two possibilities: We might have an 8 x 8
box, with small squares in the rectangle whose corners are {34, 43, cd, dc}; or we might
have a 9 x 9 box, with small squares confined to the rectangle {45, 54, de, ed}. The first
case has 69120 = 4 • 2 + 17278 • 4 solutions, four with reflective symmetry; the second
case has a whopping 157398 = 75 • 2 + 39312 • 4 solutions, with 75 classes unchanged
under reflection. Symmetric solutions of both types are shown.
306. Introduce items 0 to 9 and xy as in the previous answer, as well as pxy and #xy ;
again x and y aren’t both even, and 0 < x < 2n, 0 < y < 2m. Here pxy and #xy
are primary, but the xy items are secondary. Options of the first kind, like ‘0 p35 35:1
p37 37:1 p34 34:1 p45 45:1’, specify placement of a piece. Options of the second kind,
‘pxy xy:0’, allow square xy to be empty. Options of the third kind, either ‘#xy xy:0’
or ‘#xy xy:1 (x-2)y:a (x+2)y:b x(y-2):c x(y+2):d’ for binary variables a, b, c, d with
a + b + c + d = 2, and where both x and y are odd, enforce the snake condition for
large squares. Options of the fourth kind, either ‘#xy xy:0’ or ‘#xy xy:1 (x-1)(y-1):a
(x-1)(y+1):b (x+1)(y-1):c (x+1)(y+1):d’ and where x + y is odd, enforce the snake
condition for small squares. Nonsharp branching (exercise 10) should be used.
Those options unfortunately produce a huge number of spurious solutions con
taining 4-cycles. One can rule out the 4-cycle whose large squares have a given x'y'
as midpoint by using Algorithm M and introducing a new primary item #x'y' whose
multiplicity is [0.. 3]. (Notice that x' and y' are both even.) This primary item is
appended to every option of type 3 that begins with ‘#xy xy:1’, where xy is one of
the four squares touching point x'y'. The 4-cycles of small squares can be ruled out
similarly, with new primary items #xy !, where x+ y is even.
Every snake-in-the-box cycle of 20 large squares will fit into a box of size 3 x 9,
4x8, 5 x 7, or 6 x 6; and Algorithm M finds respectively (0, 0, 9^4, 8^8) solutions in those
four cases. Six of the eight 6 x 6 equivalence classes are, however, spurious solutions,
because their small squares form an 8-cycle and a 12-cycle instead of a single 20-
cycle. Thus there are eleven essentially different solutions. Two of each size are shown
below. [The middle two examples show two of the large squares touching at a corner.
The definition of snake-in-the-box cycles allows this to happen; but five of the eleven
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 203
solutions don’t have this “defect.” See Cubism For Fun 41 (October 1996), 30-32.] Factoring
one-sided versions
bipair
convex polygons
307. “Factoring” with the residues (i - j) mod 3 and (i + j) mod 3, we see that the
domino must go into adjacent cells with (i - j) mod 3 = 1 and (i + j) mod 3 = 2. That
means either {(3i, 3j), (3i, 3j + 1)} or {(3i + 1, 3j + 2), (3i + 2, 3j + 2)}. Conversely, it’s
easy to insert straight trominoes after placing a domino into any of those cell pairs.
308. (a) Each shape now has integer pairs of the forms (x,y) and (x,y)'. One ele
mentary transformation, which rotates by 60°, takes (x,y) ^ (x + y,xmax — x)' and
(x,y)' ^ (x + y + 1,xmax — x); its result should be adjusted afterwards so that the
coordinates are as small as possible while remaining nonnegative. The other elementary
transformation, which is a reflection, simply takes (x,y) ^ (y,x) and (x,y)' ^ (y,x)'.
For convenience, let’s write just xy for (x, y). One tetriamond is the triangle of
size 2, {00, 01,10, 00'}. It has two base placements; the other one is {01', 10', 11', 11}.
Another tetriamond is “straight,” {00, 00', 10,10'}, and it has six base placements.
(Three of them, such as {00, 00', 01, 01/}, involve reflection; hence that tetriamond
has two one-sided versions.) The remaining tetriamond is “bent,” {00z, 01,10,10'}, a
hexagon minus a diamond. Its six base placements are all obtained by rotation.
(b) Four of the 20-iamonds are convex, namely those parameterized by (6, 4, 0, 0),
(10, 10, 1, 0), (4, 2, 1, 0), and (5, 5, 2, 0) in the notation of exercise 143. But only (4, 2, 1, 0)
can be packed with the four pentiamonds — in fact in two ways, differing by a bipair.
(c) The convex 30-iamonds (15, 15, 1, 0) and (7, 7, 1, 1) cannot be packed. But
(4, 2, 1, 1), (5, 5, 3, 0), (3, 3, 3, 1) have resp ectively 3, 1, and 4 distinct solutions.
309. (a) (A, . . . , L) have resp ectively (6, 3, 6, 1, 6, 6, 12, 12, 6, 12, 12, 12) placements.
(The hexiamonds have also been given descriptive names: A = lobster (or heart);
B = butterfly (or spool); C = chevron (or bat); D = hexagon; E = crown (or boat); F =
snake (or wave); G = hook (or shoe); H = signpost (or pistol or airplane); I = bar (or
rhomboid); J = crook (or club or ladle); K = yacht (or steps); L = sphinx (or funnel).)
(b) Hexiamonds K and L are special, because they contain four triangles of one
kind (Д or V) and two of the other (V or Д). The other hexiamonds are balanced,
with three of each kind.
Eleven convex polygons are 72-iamonds, by exercise 143. Those with height less
than 4, namely (36, 36, 1, 0), (19, 17, 0, 0), (18, 18, 2, 0), and (12, 12, 3, 0), are unsolvable.
So is (9, 3, 0, 0), which is out of balance by 6. The other six are solvable; for example,
Historical notes: T. Scrutchin [U.S. Patent 895114 (1908)] described an early puz
zle based on assembling checkered polyiamonds of sizes 3-7 into a large equilateral tri
angle. The complete set of hexiamonds was perhaps first invented by Charles H. Lewis,
who submitted a paper about them to the American Mathematical Monthly in April
1958. His paper wasn’t judged worthy of publication; but a copy survives in the files
of Martin Gardner, to whom he had sent a preprint. (He’d been inspired by Martin’s
exposition of polyominoes in December 1957.) Lewis named his pieces hexotinoes, and
said that they b elonged to the family of “polotinoes,” which began with the monotino,
the dotino, the trotino, three tetrotinoes, and four pentotinoes. He knew the parity
rule, and he exhibited one of the ways to pack all 12 hexotinoes into a 6 x 6 rhombus.
Other people came up with similar ideas independently a few years later. It
was T. H. O’Beirne who coined the names “polyiamond” and “hexiamond” —to the
eternal dismay of language purists — first in letters to Richard Guy in 1960, then in
his popular weekly columns in New Scientist [12 (1961), 261, 316-317, 379, 706-707].
He introduced an intriguing problem about packing the one-sided hexiamonds into
the rosette shape formed by 19 hexagons (12 surrounding 6 surrounding 1); see pages
452-455 of FGbook for details. Martin Gardner wrote about the subject in Scientific
American 211, 6 (December 1964), 123-130, and hexiamonds were soon sold as pleasing
puzzles in Japan, Germany, the USA, and elsewhere. The 24 heptiamonds also have
many aficionados, but they are b eyond the scope of this book.
The earliest papers about hexiamonds considered mostly standard shapes like
parallelograms, or shapes that are decidedly non-convex. Polygon (6, 2, 2, 1) above,
the “diaper,” may have first appeared as problem 130 in the Russian magazine Nauka
i Zhizn’ #6 (1969), 146; #7 (1969), 101; Michael Beeler enumerated its solutions in
HAKMEM (M.I.T. A.I. Laboratory, 1972), Hack 112. Polygon (6, 6, 3, 2) has apparently
not occurred previously in print, although it has more solutions than the others.
July 26, 2019
7.2.2.1 answers to exercises 205
310. The container holds 4m+2 triangles; m = 18 doesn’t work, so we need at least six author
empty cells. The author’s favorite way constrains them to be well-separated “teeth”: Postl
heptiamond
generalized toruses
rhombuses
squarish triangles
311. H. Postl found a nice proof that N must be at least 190: Replace hexiamonds A, sex
pentomino wallpaper
G, K by the heptiamond that includes a hexagon. The twelve resulting pieces contain 75 Thoen
triangles; enlarge them by appending quarter-size triangles around all the edges. This Wetering
adds 91 trapezoids and 163 quarter-triangles. The latter must occupy at least 91 + Struyk
Gardner
(163 - 91)/3 = 115 triangles, because we can’t fill a triangle without using a trapezoid. Stead
Exercise 7-137 explains how to obtain many generalized toruses that are com Notenboom
icosahedron
posed of 95 rhombuses; so we might as well make the repeating pattern as square as
pentiamonds
possible by choosing (a, b, c, d) = (11, -4, -1, 9), as in the solution below. There are one-sided pieces
(astonishingly) 321530 such packings, each of which represents 24 different solutions
when the heptiamonds revert to {A, G, K}. The example shown is one of only 1768
solutions for which the three resulting “females” attract three neighboring “males.”
<fips
[The smallest region for pentomino wallpaper has 143 cells. See A. Thoen and A. van
de Wetering, Facets of Pentominoes (2018), 95.]
312. Adrian Struyk wrapped the octahedron with hexiamonds, and showed it to Martin
Gardner in 1964. An attractive solution by Walter Stead (1970, unpublished),
doesn’t bend any piece in more than two places. (Incidentally, Thijs Notenboom showed
in 1967 how to wrap the icosahedron with the four pentiamonds.)
313. The whirled versions of Pieces (A, ... , L) can be packed in respectively (13, 2 • 2,
10, 55 • 6, 19, 10 • 2, 9, 10, 10 • 2, 18, 6, 20) ways. But with flipped whirls, the one-sided
pieces lead to different shapes, and the counts for (F, G, . . . , L) change to (6 • 2, 7, 8,
0 • 2, 25, 7, 8). Here’s how the pattern of answer 310 looks when scaled up by 12:
related to the whirl tessellation. He was subsequently inspired to develop it much Escher
further; see The World of M. C. Escher (1971), plates 84 and 199.] Alhambra
tessellation
314. To make the same shape from two pairs {a, b} and {c, d} of polyiamonds (or polyforms
one-sided
polyominoes, etc.), choose an n-celled region A into which any solution will fit. Use author
four primary items {a,b, c, d} and 6n secondary items 0a, 1a, aa, ba, ca, da for each Pegg Jr.
cell a. For each placement ‘a a1 ... as’ in A, and each of the 2s sequences q1 . . .qs Golomb
pentominoes
with qk € {c, d}, create the option ‘a 0a1 q1a1 ... 0as qsas ав1 ... a/in-s, where even/odd coordinate
{в1,... , en-s} = A \ {a1,... , as}. Also create similar options for each placement of b, Marlow
c, d, with the roles of (0, a, c, d) replaced respectively by (0, b, c, d), (1, c, a, b), (1, d, a, b). Schwartz
Noshita
Choose one of {a, b, c, d} (one-sided if possible) and restrict it to a single place propeller
ment. For the pentiamond problem, the author chose the piece a that includes a tetra Schwartz
Edgar
hedron, and placed it in the center of a 70-iamond A. There are three separate cases, Gardner
depending on which piece is called b ; they yielded three huge exact cover problems, each Gosper
of which had 15300 options of length 76 (thus total length 1.2 million). Yet Algorithm X flowsnake
fractal
solved each problem in at most 1.5 G^, including 0.3 G^ just to load the data. ___ Vince
The answer, as Sicherman observed, is unique. [See Ed Pegg Jr.’s blog, (/—(
www.mathpuzzle.com/30November2008.html. Solomon Golomb, in Recreational \_A
Math. Mag. #5 (October 1961), 3-12, had shown that the twelve pentominoes A /
can be partitioned into three sets of four, each of which make congruent pairs.] \ \
315. Proceed as in answer 308, but simply let (x,y) ^ (x + y,xmax — x); ignore (x,y)z.
[There’s also an even/odd coordinate system for hexagons, with hexagon xy
represented by (2x + 1, 2y + 1), and the edge between adjacent hexagons represented
by their average. Then 60° rotation takes (x,y) ^ (x + y — 1, xmax — x + 1).]
316. There are 12290 • 12 solutions, and it’s not hard to find one by hand. (The first
solutions were discovered independently by T. Marlow and E. Schwartz in 1966; the
total number was found by K. Noshita in 1974.) The example shown here
has the trihexes “maximally separated.” [The seven tetrahexes pack the jAJJ XjJ
rhomboid {xy | 0 < x< 4, 0 < y < 7} in 9 • 2 ways, and the skew triangle f f ATI j
{xy | 0 < x < 7, x < y < 7} in 5 • 2 ways; but they can’t pack the triangle
{xy | 0 < x< 7, 0 < y< 7 — x}.] ХСХ/
317. The scaled-up “bar,” “wave,” and “propeller” cannot be packed. But the “bee,”
“arch,” “boot,” and “worm” are doable in respectively 2 • 2, 1, 10, and 4 ways, such as
• AA • BB • • • • • •
C • DD • E • • • •
• • • • F..... •gg
• AA • BB • • • • • •
C
D • • D
E
F • • FF • G • •
• • • •bb C • • • • • • • EE • • • FF • • F G • •
A
• •
A
• •bb C • • CC D
•
D
• • EE • • •••••F •gg
A A • CC • • DD • • •ee •gg
• • • K •••L NN • • • •
• • HH • • II • • II • • J J • • JJ• • • • K L L • L • • MM • • • • NN • •
HH • • HH • • • • • • JJ• • J K • •K •LL• • • MM • • • • NN • •
• • • •hh II II ••••••J K • •K •LL• MM • • MM • • • •nn
• KK •
This scheme sets up a one-to-one correspondence between n-aboloes and 2n-ominoes
on the “H-grid,” which is the set of all pixels (x,y) with |_x/2_| + \_y/2\ even. (Each
2n-omino is kingwise connected; it actually consists of n dominoes.)
Formally speaking, let’s divide every square cell into four quarters, by cutting at
the diagonals. Then every n-abolo occupies 2n quarters; and the (north, east, south,
west) quarters of cell (x, y), in polyabolo coordinates, correspond respectively to cells
(2x — 2y, 2x + 2y) + ((0, 1), (1, 1), (1, 0), (0, 0)) of the H-grid.
[After first seeing the H-grid versions of the tetraboloes, the author felt a foolish
but irresistible urge to pack them into a 10 x 12 box, putting seven of them in the
H-grid and the other seven in the complementary H-grid, leaving eight vacant pixels
at the sides. This corresponds to putting the tetraboloes into two layers of a certain
frame that’s capable of holding 29 halfsquares. It turned out that there are 305 • 8 ways
to do this (found by Algorithm X in 10 G^). For example:
• DD • • M MLLMM •
DGGDCB BMMLLN
DGGDCB BMMLLN
GDDBBC HKLNNJ
GCCBBC HKLNNJ
• ggccf KHNKJE
• ffaaf KHNKJE
FAAFFH HKKEEJ
FAAI IH HI IEEJ
• iiaai I EEJ J •
Nowadays, polyaboloes are often called “polytans,” based on their connection to classi
cal tangram puzzles from 18th-century China. T. H. O’Beirne introduced polyaboloes
in New Scientist 13 (18 January 1962), 158-159.]
320. Every convex polyabolo can be characterized by six more-or-less independent
parameters: We start with an m x n rectangle, then cut off triangles of sizes a, b, c, d at
the lower left, lower right, upper right, and upper left corners, where a+b < n, b+c < m,
c + d < n, and d + a < m. The number of halfsquares is N = 2mn — a2 — b2 — c2 — d2.
To avoid duplicates, we require m < n, and insist that (a, b, c, d) be lexicographically
greater than or equal to (b, a, d, c), (c, d, a, b), (d, c, b, a). Furthermore, if m = n, this
4-tuple (a, b, c, d) should also be lexicographically greater than or equal to (a, d, c, b),
(b, c, d, a), (c, b, a, d), (d, a, b, c).
July 26, 2019
208 ANSWERS TO EXERCISES 7.2.2.1
The smallest positive area achievable with m < n is 2m(n - m) halfsquares; and O’Beirne
when m = n the smallest is 2n — 1. Thus we must have n < (N + 2)/2, and it’s feasible Ainley
Picciotto
to backtrack through a finite number of cases. Wang
There are 63 solutions when N = 56. But most of them are unpackable, because of Hsiung
OEIS
an important property noted by T. H. O’Beirne in 1962: Exactly five of the tetraboloes, Fox-Epstein
namely {E, G, J, K, L}, have an odd number of unmatched 2 sides in each direction. Gardner
It follows that a + c (and b + d) must be odd. even/odd coordinate system
Just 10 of the 63 solutions pass this extra test. Two of those ten— (1 x 29; 1,1, 0, 0)
and (3x 11; 3,1, 0, 0) —don’t work. But the other eight are achievable:
Most of them were cracked by E. S. Ainley in 1965; but H. Picciotto found ‘*’ in 1989.
[This enumeration problem was first studied by F. T. Wang and C.-C. Hsiung,
AMM 49 (1942), 596-599, who proved that there are 20 convex 16-aboloes. The totals
for general N are OEIS sequence A245676, contributed by E. Fox-Epstein in 2014.]
321. [In a letter to Martin Gardner dated 12 March 1967, O’Beirne said that
he now knew of 13 solutions, with help from several readers. “Are these the
lot?” The answer is yes: The total is indeed 13. The solution shown here
leads to three of the others, via tricky rearrangements.]
322. (i) We can reduce polysticks to (disconnected) p olyominoes, by 3-fold enlarge
ment: Let vertex ij of a square grid correspond to pixel (3i)(3j); and let the line segment
between adjacent vertices ij — i'j' correspond to the two pixels between (3i)(3j) and
(3/ )(3j'). Placements can intersect each other occur only at internal pixels where two
parallel segments touch; we can prevent crossing by making such pixels secondary.
For example, to pack the 6 x 6 array in the example, we use the pixels xy for
0 < x, y < 18, where x or y is a multiple of 3; item xy is secondary if 3 divides both x
and y. One of the options for the T-shaped tetrastick is ‘04 05 07 08 16 26 36 46 56’;
one of the options for the V-shaped tetrastick is ‘34 35 36 37 38 49 59 69 79 89’. The
secondary item 36 ensures that these options won’t both be chosen simultaneously.
(ii) Instead of scaling up by 3, we can scale up by 2, as in the even/odd coordinate
system, by letting vertex ij correspond to pixel (2i)(2j). Then segment ij — i'j'
corresponds to pixel (i + i')(j + j'); and the 6 x 6 example involves primary items xy
for 0 < x, y < 12 with x + y odd, together with secondary items xy with x and y both
even. The example T and V options in this scheme become ‘03 05 14 24 34’ and ‘23 24
25 36 46 56’; now it’s the secondary item 24 that keeps them from interacting.
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 209
Scheme (i) can be used without change to answer 266. Scheme (ii) is almost 90° rotation
twice as fast; but answer 266 must then be modified so that it never shifts by odd Barwell
Benjamin
amounts. (Notice, for example, that the O and X tetrasticks each have only one base Dawson
placement in scheme (ii), namely ‘01 10 12 21’ and ‘12 21 23 32’. Shifting by 11 would Jelliss
change O to X and vice versa!) Thus, 90° rotation must be redefined as (x,y) ^ spin
Owen
(y,xmax + (xmax & 1) - x), in the modified answer 266; also, Sx and Sy must be even. tetrominoes
[Polysticks were named and explored by B. R. Barwell in JRM 22 (1990), 165 dual
Keller
175. They had actually been studied in the 1940s by H. D. Benjamin and T. R. Dawson
in the 1940s, who already knew how to pack the pieces for n < 4 into a 6 x 6 grid; see
G. P. Jelliss, JRM 29 (1998), 140-142. See also FGbook, pages 457-472.]
323. (a) For example, the vertices (m, n) of an ordinary square grid can be skewed to
(m,n)' = (m — (n mod2)e,n — (m mod2)e), where б is the degree of skew.
Notice that each square of the skewed grid has a clockwise or counterclockwise “spin.”
(b) There’s a nice way to represent each square as a 5-pixel cross, and each
rhombus as a 3-pixel diagonal. For example, here are pixel equivalents of the tetraskews:
k....... • • i •••• q Q ••• • Ss • • • •
• I • • il • • i • k...... • l..... •
qQQQ S S S s • • •
Illil I li • • Kk • k K • ILl •• L • • QqQq • S• Ss • s
• li •• li •• KKKkKKK LLLlLLL qqqq • • • S S Ss •
• Kk • • K • • L •• IL • • Qq •• • • • Ss • •
• •tT• • t • • uU • • u v • • vv• • • • •y• • • • • • Z• • z
• ttttt • • uuuuu • • vvvvv • • • YYY • • • • ZZZz•
t • tTt • • u • • UuU • • • vV • Vv • Y yY • Y • • ZzZz• •
• • •t • • • • • • •uuu • • • •vvv YYYyYYY Z Z Z z • • •
• • • •t • • .... U • V• • Y • • yY • • Z• • z• •
(Lowercase letters indicate the rhombuses here only for clarity; all pixels are either “in”
or “out.” The shapes fit together only when squares and rhombuses alternate properly.)
(c) The 4 x 10 frame in the example has 486 solutions; the analogous 5 x 8 frame
has 572; these were first enumerated by Brendan Owen in 2000. There are 3648 ways
to fit the pieces into a 2 x 21 frame, but 2 x 20 is too tight.
However, those counts can be divided by 2, because solutions to this problem
come in pairs. Consider an arrangement of ten unskewed tetrominoes that involves
one square, one straight, two skews, two tees, and four ells. It can be skewed in four
ways, because we have two choices for which cells should be rhombuses and two choices
for the spins; and it will be a valid skewed solution if and only if the resulting ten
tetraskews are distinct. Changing the spins of a valid solution always gives another
valid solution in which K о L,S о Z, U о V are swapped. Every solution therefore
has a dual, which looks rather different but is well defined.
For example, the 486 solutions to the 4 x 10 rectangle problem correspond to
exactly 226 unskewed arrangements that are distinct under reflections, 17 of which
actually yield two dual pairs of skewed solutions, in which the roles of squares and
rhombuses are reversed! Here’s one such case:
;
[Michael Keller named the polyskews in 1993, and found a way to pack
the tetraskews into two 4 x 5 frames, thus solving the 4x 10 and 5 x 8 rectangles
simultaneously. (See World Game Review 12 (1994), 12. That problem has
just 24 solutions.) Generalizations to 3D await investigation.]
July 26, 2019
210 ANSWERS TO EXERCISES 7.2.2.1
References: Polyforms live on many excellent and well-illustrated websites — no Goodger
tably puzzler.sourceforge.net by David Goodger; www.polyforms.eu by Peter Esser; Esser
Zucca
www.iread.it/lz/polymultiforms2.html by Livio Zucca; userpages.monmouth.com/ Sicherman
~colonel/polycur.html by George Sicherman; www.recmath.org/PolyPages/ by An Clarke
Abaroth
drew Clarke; abarothsworld.com/Puzzles.htm by Abaroth. In particular, Abaroth’s reduce one polyform to another
page “Squaring the Hexagon” discusses many ways to reduce one polyform to another. Pegg
See also Ed Pegg Jr.’s chapter in Tribute to a Mathemagician (2005), 119-125. multigraph
pendant vertex: of degree 1
324. The same ideas apply, but with three coordinates instead of two, and with the repeated edges
diameter
elementary transformations (x,y,z) ^ (y,xmax — x,z), (x,y,z) ^ (y,z,x). Guy
Pieces (1, 2, . . . , 7) have respectively (12, 24, 12, 12, 12, 12, 8) base placements, Conway
leading to 144 + 144 + 72 + 72 + 96 + 96 + 64 options for the 3 x 3 x 3 problem. Guy
Berlekamp
325. It’s tempting, but wrong, to try to compute the Somap by considering only the Conway
Guy
240 solutions that have the tee in a fixed position and the claw restricted; the pairwise Gardner
semidistances between these special solutions will miss many of the actual adjacencies.
To decide if u ——— v, one must compare u to the 48 solutions equivalent to v.
(a) The strong Somap has vertex degrees 71 67 519 431 359 263 145 015; so an “average”
solution has (1 • 7 + 7 • 6 + • • • + 15 • 0)/240 ~ 2.57 strong neighbors. (The unique vertex
of degree 7 has the level-by-level structure 35552 33
3 4 1
61 77 42 from bottom to top.)
74 1
652 662
This graph
has two edges between 53552 3343 1 76 42 and 3
614 6
752 772 ,
53334 611 622, so it’s actually a multigraph.
144 676
554 752 772
The full Somap has vertex degrees 212 181 169 1513 1410 1316 1217 1112 1016 928 826
725 626 516 417 33 2111 01, giving an average degree ~ 9.14. (Its unique isolated vertex
,
432 466 715 , and its only pendant vertex is 433353 476555 771711 .
is 462
333 455 115
762 772
333 755 771
222 462 466 ,
Two other noteworthy solutions
466 762 772 ,
336 452 755 and 331 452 712 , are the only ones that contain the two-piece substructure ЛЙ.
466 765 772
327. (a) The solution counts, ignoring symmetry reduction, are: 4 x 5 corral (2), symmetries
gorilla (2), smile (2), 3 x 6 corral (4), face (4), lobster (4), castle (6), bench (16), Hein
Parker Brothers
bed (24), doorway (28), piggybank (80), five-seat bench (104), piano (128), shift 2 Carlson
(132), 4 x 4 coop (266), shift 1 (284), bathtub (316), shift 0 (408), grand piano (526), Hall
Hill
tower 4 (552), tower 3 (924), canal (1176), tower 2 (1266), couch (1438), tower 1 (1520), Kenworthy
stepping stones (2718). So the 4 x 5 corral, gorilla, and smile are tied for hardest, while Morgan
stepping stones are the easiest. (The bathtub, canal, bed, and doorway each have four Murray
Smiley
symmetries; the couch, stepping stones, tower 4, shift 0, bench, 4 x 4 coop, castle, Farhi
five-seat bench, piggybank, lobster, piano, gorilla, face, and smile each have two. To symmetries
get the number of essential ly distinct solutions, divide by the number of symmetries.) Bundgard
McFarren
(b) Notice that the stepping stones, canal, bed, and doorway appear also in (a).
The solution counts are: W-wall (0), almost W-wall (12), bed (24), apartments 2 (28),
doorway (28), clip (40), tunnel (52), zigzag wall 2 (52), zigzag wall 1 (92), underpass
(132), chair (260), stile (328), fish (332), apartments 1 (488), goldfish (608), canal
(1176), steps (2346), stepping stones (2718); hence “almost W-wall” is the hardest of
the possible shapes. Notice that the stepping stones, chair, steps, and zigzag wall 2 each
have two symmetries, while the others in Fig. 80(b) all have four. The 3x3x3 cube, with
its 48 symmetries, probably is the easiest possible shape to make from the Soma pieces.
[Piet Hein himself published the tower 1, shift 2, stile, and zigzag wall 1 in his
original patent; he also included the bathtub, bed, canal, castle, chair, steps, stile,
stepping stones, shift 1, five-seat bench, tunnel, W-wall, and both apartments in his
booklet for Parker Brothers. Parker Brothers distributed four issues of The SOMA9
Addict in 1970 and 1971, giving credit for new constructions to Noble Carlson (fish,
lobster), Mrs. C. L. Hall (clip, underpass), Gerald Hill (towers 2-4), Craig Kenworthy
(goldfish), John W. M. Morgan (face, gorilla, smile), Rick Murray (grand piano), and
Dan Smiley (doorway, zigzag wall 2). Sivy Farhi published a booklet called Somacubes
in 1977, containing the solutions to more than one hundred Soma cube problems
including the bench, the couch, and the piggybank.]
328. By eliminating symmetries, there are (a) 421 distinct cases with cubies omitted on
both layers, and (b) 129 with cubies omitted on only one layer. All are possible, except
in the one case where the omitted cubies disconnect a corner cell. The easiest of type (a)
omits {000, 001, 200} and has 3599 solutions; the hardest omits {100, 111, 120} and has
45^2 solutions. The easiest of type (b) omits {000, 040, 200} and has 3050 solutions; the
hardest omits {100,110,140} and has 45 • 2 solutions. (The two examples illustrated
have 821 • 2 and 68 • 4 solutions. Early Soma solvers seem to have overlooked them!)
329. (a) The 60 distinct cases are all quite easy. The easiest has 3497 solutions and uses
{002, 012, 102} on the top level; the hardest has 268 solutions and uses {002, 112, 202}.
(b) Sixteen of the 60 possibilities are disconnected. Three of the others are also im
possible — namely those that omit {01z, 13z, 21z} or {10z, 11z, 12z} or {10z, 11z, 13z}.
The easiest has 3554 solutions and omits {00z, 01z, 23z}; the hardest of the possibles
has only 8 solutions and omits {00z, 12z, 13z}.
(The two examples illustrated have 132 • 2 and 270 • 2 solutions.)
330. T. Bundgard and C. McFarren found in 1999 that all but 216 are realizable
[www.fam-bundgaard.dk/SOMA/NEWS/N990308.HTM]. Five cases have unique (1 • 2) solu-
tions:
331. Every polycube has a minimum enclosing box for which it touches all six faces. If secondary item
those box dimensions a x bx c aren’t too large, we can generate such polycubes uniformly author
Skj0de Skjern
at random in a simple way: First choose 27 of the abc possible cubies; try again if that Knutsen, see Skj0de Skjern
choice doesn’t touch all faces; otherwise try again if that choice isn’t connected. Kustes
Morgan
For example, when a = b = c = 4, about 99.98% of all choices will touch all faces, Schwartz
and about 0.1% of those will be connected. This means that about .001 (244) ~ 8 x 1014 Conway
of the 27-cubie polycubes have a 4 x 4 x 4 b ounding box. Of these, about 5.8% can be Gardner
the more exotic shapes that are possible, as seen from behind and below: gravitationally stable
Francillon
Hoffmann
Mikusinski’s Cube
Steinhaus
pentacubes
Reid
There also are ten surprising ways to make the cube facade if we allow hidden “un Sicherman
. 446 . . 744. . 333 . . Holy Grail
derground” cubies: The remarkable construction . . . 55 72 .. 65
. 5 .. 7766
2 231. .. . raises the entire
. 211
Shindo
cube one level above the floor, and is gravitationally stable, by exercise 333’s criteria! Neo Diabolical Cube
factor
Unfortunately, though, it falls apart — even with a heavy book on top. ell trominoes, see bent trominoes
[The false-front idea was pioneered by Jean Paul Francillon, whose construction bent trominoes
of a fake W-wall was announced in The SOMA® Addict 2,1 (spring 1971).] right trominoes, see bent trominoes
solid bent trominoes
335. (a) Each of 13 solutions occurs in 48 equivalent arrangements. To remove the L-cube puzzle
symmetry, place piece 7 horizontally, either (i) at the bottom or (ii) in the middle. In
case (ii), add a secondary ‘s’ item as in answer 268, and append ‘s’ also to all placements
of piece 6 that touch the bottom more than the top. Run time: 400 Ku.
[This puzzle was number 3-39 in Hoffmann’s Puzzles Old and New (1893). An
other 3 x 3 x 3 polycube dissection of historical importance, “Mikusinski’s Cube,” was
described by Hugo Steinhaus in the 2nd edition of his Mathematical Snapshots (1950).
That one consists of the ell and the two twist pieces of the Soma cube, plus the
pentacubes B, C, and f of exercise 340; it has 24 symmetries and just two solutions.]
(b) Yes: Michael Reid, circa 1995, found the remarkable set
C C C
is the long-sought “Holy Grail” of 3 x 3 x 3 cube decompositions: Its pieces not only
have flatness and double uniqueness, they are nested (!!). There’s also Yoshiya Shindo’s
known as the “Neo Diabolical Cube” (1995); notice that it has 24 symmetries, not 48.
336. This piece can be modeled by a polycube with 20 + 20 + 27 + 3 cubies, where
we want to pack nine of them into a 9 x 9 x 9 box. Divide that box into 540 primary
cells (which must be filled) and 189 secondary cells (which will contain the 27 cubies
of the simulated dowels). Answer 324 now yields an exact cover problem with 1536
options; and Algorithm X needs only 33 Mu to discover 24 solutions, all equivalent by
symmetry. (Or we could modify answer 324 so that all offsets have multiples of 3 in
each coordinate; then there would be only 192 options, and the running time would go
.
down to 8 Mu.) One packing is 443 ,
123 167 887, with dowels at 010 070 000.
849 899 030 080 000 .
One might be tempted to factor this problem, by first looking at all ways to pack
nine solid bent trominoes into a 3 x 3 x 3 box. That problem has 5328 solutions, found
in about 5 Mu; and after removing the 48 symmetries we’re left with just 111 solutions,
into which we can try to model the holes and dowels. But such a procedure is rather
complicated, and it doesn’t really save much time, if any.
July 26, 2019
214 ANSWERS TO EXERCISES 7.2.2.1
Ronald Kint-Bruynseels, who designed this remarkable puzzle, also found that it’s Kint-Bruynseels
possible to drill holes in the solid cubies, parallel to the other two, without destroying even/odd coordinates
Spots Puzzle
the uniqueness of the solution(!). [Cubism For Fun 75 (2008), 16-19; 77 (2008), 13-18.] Hoffmann
historical notes
337. Let’s use even/odd coordinates as in exercise 145, so that each final face has one Wolff
coordinate in {0, 6} and two coordinates in {1, 3, 5}. The first goal has red sp ots on Twice Dice
faces 330, 105, 501, 015, 033, 051, 611, 615, 651, 655, 161, 165, 363, 561, 565, 116, Pentangle Puzzles
straight tetracube
136, 156, 516, 536, 556. The other goal has green sp ots on 19 of those 21 faces; but square tetracube
303 replaces 033 and 633 replaces 363. (For simplicity, we’ll ignore alternative setups; Meeus
there actually are sixteen ways to put sp ots on dice, not just two.) Yoshigahara
cuboid
Nine bent tricubes will pack a 3 x 3 x 3 cube in 5328 ways. (They fall into 111 Besley
equivalence classes of size 48, under rotation and reflection; but that fact is irrelevant Patent
Historical notes
here.) Take any such solution and color its 54 external faces with the red solution.
Then see if its pieces can be rearranged to give the green solution.
Notice that each bent tricube has fourteen square faces; but the two “inner” faces
are never visible in the final assembly. That assembly will specify from 2 to 7 of the
12 potential faces, leaving 5 to 10 faces unconstrained. Altogether we’ll have 21 faces
specified red, 33 specified blank, and 54 still free.
It turns out that 371 of the 5328 red solutions can be rearranged into green
solutions; in fact one case leads to 6048 different green solutions! And there are 52
combinations of red+green solutions that leave 18 faces unspecified, such as this:
Й
rtXXi |с|Ц5 гШй
We’re free to put anything we like on those 18 faces — giving red or green sp ots that are
false clues, and/or concealing a third pattern that the puzzler is challenged to achieve.
(The classic “Spots Puzzle” in Hoffmann’s Puzzles Old and New (1893), No. 3-17,
distributed by E. Wolff & Son’s pencil company, assembled a single die from straight
tricubes. Lavery’s elegant “Twice Dice” was produced by Pentangle Puzzles in 1990.)
338. The straight tetracube and the square tetracube ^^|, together with
the size-4 Soma pieces in (39), make a complete set.
We can fix the tee’s position in the twin towers, saving a factor of 32; and each
of the resulting 40 solutions has just one twist with the tee. Hence there are five
inequivalent solutions, and 5 • 256 altogether.
The double claw has 63 • 6 solutions. But the cannon, with 1 • 4 solutions, can be
formed in essentially only one way. (Hint: Both twists are in the barrel.)
There are no solutions to ‘up 3’. But ‘up 4’ and ‘up 5’ each have 218 • 8 solutions
(related by turning them upside down). Gravitationally, four of those 218 are stable
for ‘up 5’; the stable solution for ‘up 4’ is unique, and unrelated to those four.
References: Jean Meeus, JRM 6 (1973), 257-265; Nob Yoshigahara, Puzzle World
No. 1 (San Jose: Ishi Press International, 1992), 36-38.
339. All but 48 are realizable. The unique “hardest” realizable case, Qjj|, has 2 • 2
solutions. The “easiest” case is the 2 x 4 x 4 cuboid, with 11120 = 695 • 16 solutions.
340. (a) A, B, C, D, E, F, a, b, c, d, e, f, j, k, l, . . . , z. (It’s a little hard to see why
reflection doesn’t change piece ‘l’. In fact, S. S. Besley once patented the pentacubes
under the impression that there were 30 different kinds! See U.S. Patent 3065970
(1962), where Figs. 22 and 23 illustrate the same piece in slight disguise.)
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 215
Historical notes: R. J. French, in Fairy Chess Review 4 (1940), problem 3930, French
was first to show that there are 23 different pentacube shapes, if mirror images are Hansson
chirality
considered to be identical. The full count of 29 was established somewhat later by hexacubes
F. Hansson and others [Fairy Chess Review 6 (1948), 141-142]; Hansson also counted heptacubes
Niemann
the 35 + 77 = 112 mirror-inequivalent hexacubes. Complete counts of hexacubes (166) Baillie
and heptacubes (1023) were first established soon afterwards by J. Niemann, A. W. cuboids
Baillie, and R. J. French [Fairy Chess Review 7 (1948), 8, 16, 48]. symmetry-breaking
Nixon
(b) The cuboids 1x3x20, 1x4x15, 1x5x12, and 1x 6x 10 have of course already Hansson
been considered. The 2 x 3 x 10 and 2 x 5 x 6 cuboids can be handled by restricting X Bouwkamp
Guy
to the bottom upper left, and sometimes also restricting Z, as in answers 268 and 270; Dorie
we obtain 12 solutions (in 350 Мд) and 264 solutions (in 2.5 Од), respectively. Dorian cube
The 3 x 4 x 5 cuboid is more difficult. Without symmetry-breaking, we obtain pentominoes
Sillke
3940 x 8 solutions in about 200 Од. To do better, notice that O can appear in four partition
essentially different positions. With four separate runs we can find 5430/2 + 1348/4 + author
geek art
716/2 + 2120/4 = 3940 solutions, in 35.7 + 10.0 + 4.5 + 7.1 w 57 Од. Sillke
[The fact that solid pentominoes will fill these cuboids was first demonstrated by
D. Nixon and F. Hansson, Fairy Chess Review 6 (1948), problem 7560 and page 142.
Exact enumeration was first performed by C. J. Bouwkamp in 1967; see J. Combina
torial Theory 7 (1969), 278-280, and Indagationes Math. 81 (1978), 177-186.]
(c) Almost any subset of 25 pentacubes can probably do the job. But a particu
larly nice one is obtained if we simply omit o, q, s, and y, namely those that don’t fit
in a 3 x 3 x 3 box. R. K. Guy proposed this subset in Nabla 7 (1960), 150, although
he wasn’t able to pack a 5 x 5 x 5 at that time.
The same idea occurred independently to J. E. Dorie, who trademarked the name
“Dorian cube” [U.S. Trademark 1,041,392 (1976)].
An amusing way to form such a cube is to make 5-level prisms in the shapes of the
P, Q, R, U, and X pentominoes, using pieces {a, e, j, m, w}, {f, k, l, p, r}, {A, d, D, E, n},
{c, C, F, u, v}, {b, B, t, x, z}; then use the packing in answer 269(!). This solution can
be found with six very short runs of Algorithm X, taking only 300 megamems overall.
Another nice way, due to Torsten Sillke, is more symmetrical: There are 70,486
ways to partition the pieces into five sets of five that allow us to build an X-prism in
the center (with piece x on top), surrounded by four P-prisms.
One can also assemble a Dorian cube from five cuboids, using one 1 x 3 x 5, one
2 x 2 x 5, and three 2 x 3 x 5s. Indeed, there are zillions more ways, too many to count.
341. (a) Make an exact cover problem in which a and A, b and B, . . . , f and F are
required to be in symmetrical position; there are respectively (86, 112, 172, 112, 52, 26)
placements for such 10-cubie “super-pieces.” Furthermore, the author decided to force
piece m to be in the middle of the top wall. Solutions were found immediately! So piece
x was placed in the exact center, as an additional desirable constraint. Then there were
exactly 20 solutions; the one below has also n, o, and u in mirror-symmetrical locations.
(b) The super-pieces now have (59, 84, 120, 82, 42, 20) placements; the author also
optimistically forced j, k, and m to be symmetrical about the diagonal, with m in the
northwest corner. A long and apparently fruitless computation (34.3 teramems) ensued;
but — hurrah — two closely related solutions were discovered at the last minute.
(c) This computation, due to Torsten Sillke [see Cubism For Fun 27
(1991), 15], goes much faster: The quarter-of-a-box shown here can be packed ~ЩХГ
with seven non-x pentacubes in 55356 ways, found in 1.3 Од. As in answer 294, xtljt
this yields a new exact cover problem, with 33412 different options.
July 26, 2019
216 ANSWERS TO EXERCISES 7.2.2.1
Another 11.8 Gu then yields seven suitable partitions into four sets of seven, one Kunzell
of which is illustrated below. [See also Cubism For Fun 49 (1999), 26.] Farhi
Farhi
weighted factorization
l l l q q q q m o o o o o s v E
z z t A A
l o o o o o q m m x q q q q E E
z s t t t
f f u u u F F m x x x b b b E z
z s t F F
D f u m u F d r n x e e b a f s
f s a F k
l l f D D D m m m d d d
F q q m m m r r n e e a a a a b q s v E
E f B s
f w a k k k F t A
l f f C C D D m d d c c
F F r t m r r n n n e a D D D b q s v f
E f B B
w w a k k D F F A
v v v B C C C x c c c b
r r r t t t r E p p p v C C D D s s v v
v B B w
w x a a D D y A A
v w B B B B x x x b b b
b r z t w w E E E p p v F C C C s z u u
u j j x
j x x D D y y y y
v w w A A A A x a a a a
z z z w w B E A A v v v F F F z z z u p u m C x c d o o o o o
k k w w E E A n a e e y z j j w l B B A d c f f k k F z j j p p e m m m C b c d d n n n l
k k s s s E E n e e y y y y j l l B A A d c c f k k k u u j p p e e m C C b c c d d n l l
s E n n n e y A d d c f f k e C q b b c d
s s P t t t y B B d c u u u e e q b r n n
k s P p t j y l l l
y u j u p e q r r r l
k k P p t j j l y y y y j j p q q r l l l
(a) (b) (c)
342. As in previous exercises, the key is to reduce the search space drastically,
by asking for solutions of a special form. (Such solutions aren’t unlikely, because
pentacubes are so versatile.) Here we can break the given shape into four pieces:
Three modules of size 33+23 to be packed with seven pentacubes, and one of size
43 — 3 • 23 to be packed with eight pentacubes. The first problem has 13,587,963
solutions, found with 2.5 Tu of computation; they involve 737,695 distinct sets
of seven pentacubes. The larger problem has 15,840 solutions, found with 400 Mu and
involving 2075 sets of eight. Exactly covering those sets yields 1,132,127,589 suitable
partitions; the first one found, {a, A, b, c, j, q, t, y}, {B, C, d, D, e, k, o}, {E, f, l, n, r, v, x},
{F, m, p, s, u, w, z}, works fine. (We need only one partition, so we needn’t have com
puted more than a thousand or so solutions to the smaller problem.)
Pentacubes galore: Since the early 1970s, Ekkehard Kunzell and Sivy Farhi have
independently published booklets that contain hundreds of solved pentacube problems.
343. We can use an instructive variety of methods to deduce that the tallest towers
have heights (hO, hP, . . . ,hZ) = (12, 29, 28, 28, 29, 25, 26, 23, 24, 17, 28, 27): Case O
is trivial. A perfect tower for P was published by S. Farhi in Pentacubes, 5th edition
(1981), Fig. 78. And it’s easy to show that hW < 24, because r, t, v, x, z can’t be placed.
Factorization yields most of the upper bounds. For example, let the cells of a
tower for R be {00k, 01k, 11k, 12k, 21k | 1 < k < h}, and add a new “weight” column
to the exact-cover matrix, representing the sum of all items/columns 00k and 12k.
(Thus the option ‘y 212 311 312 412 512’ has weight 4.) An exact cover by disjoint
options/rows will then make the new column sum 2h. But the maximum weights of
the pentacubes (a, A, . . . , f, F, j, k, . . . , z) are respectively (1, 1, 1, 1, 3, 3, 3, 3, 2, 2, 2,
2, 2, 2, 1, 1, 3, 5, 3, 4, 2, 3, 0, 3, 0, 0, 0, 4, 0). Their sum is 57; hence hR < 57/2 < 29.
Similar arguments prove that hU < 27, hV < 24, hX < 18, hZ < 28. But case T
is more complicated. Let’s introduce a column for the weights (100 • 00k) + (100 • 02k) +
(10 • 11k) + (101 • 21k), and compute the 29 maximum weights (312, 312, 310, 310, 311,
311, 221, 221, 210, 210, 220, 220, 220, 210, 211, 210, 310, 505, 323, 414, 300, 323, 400,
400, 400, 300, 200, 414, 400). The heaviest 27 sum to 8296, which is less than 311 • 27;
hence hT < 27. And if hT = 26, further study shows that we must omit x and two of
{e, E, k, m}. Moreover, each piece must use an option of maximum weight, except that
c and C should use weight 310. These restrictions narrow down the search considerably;
Algorithm X is able to prove that hT < 26 in 11 Tu (and Algorithm M in 7.6 Tu).
July 26, 2019
7.2.2.1 answers to exercises 217
It’s difficult to prove that hQ < 29, and even harder to prove that hY < 29. But Bouwkamp
in both cases a suitable weighted factorization makes the calculations feasible. (See Klarner
even/odd coordinates
www.math.uni-bielefeld.de/~sillke/polycube/tower/pentacube.) Vier Farben Block
Such weights also greatly accelerate the successful searches, for towers of maxi Geerinck
torus, 3D
mum height. Here are some that were hardest-to-find (add piece ‘s’ atop the first one): SAT solver
344. Reduce the placements that occupy the center cell from 72 to 3. That problem has
2528 solutions, found by Algorithm X in 25 G//; and those solutions form 1264 mirror-
symmetric pairs. [See C. J. Bouwkamp and D. A. Klarner, JRM 3 (1970), 10-26.]
345. A variation of even/odd coordinates works nicely: Let the pieces fill 13 cells
like (x, y, z)+{(±1, ±1, ±3), (1, ±1, ±1)}, xyz odd, where
the items (x,y,z) for 0 < x,y < 10 and 0 < z < 6 001122 001122 001122 001122
001122 888899 888899 001122
are primary for x, y, z even and secondary for x, y, z odd. 334444 834894 83b89b 33bbbb
334444 a34a94 a3ba9b 33nnnn
The solution is unique. [This puzzle, marketed as “Vier 556677 aaaa99 aaaa99 556677
Farben Block,” was designed by T. Geerinck in 2004.] 556677 556677 556677 556677
346. (a) Shifting by multiples of (0, 1, 1) gives N disjoint tripods whose corners are on
layer 0 of the torus, filling all cells of that layer except for a (possibly broken) diagonal,
and also filling all cells of such a diagonal on layer 1. We can plug the holes on layer 0
by appropriately placing N tripods whose corners are on layer N - 1. And so on.
(b) Here’s a way to pack twelve of them into a 3 x 6 x 6 torus. (Is 7/9 optimum?)
[Notes: Sherman Stein initiated the study of tripods (actually an n-dimensional Stein
generalization called “semicrosses”) in IEEE Trans. IT-30 (1984), 356-363; see also semicrosses
Hamaker
his paper with W. Hamaker on pages 364-368. They proved that the function r(n) = Morgan
r(n,n,n) is Q(n1'516), and that r(l,n,n)/n approaches a limit as n ^ to. The initial Szabo
Ostergard
values (r(1), . . . , r(9)) = (1, 2, 5, 8, 11, 14, 19, 23, 28) were found by C. Morgan, in an
Pollanen
undergraduate project at the University of Warwick in 2000; see also S. Szabo, Ann. Tiskin
Univ. Sci. Budapestiensis, Sect. Computatorica 41 (2013), 307-322. With extensive Wagon
Bower
computations, P. R. J. Ostergard and A. Pollanen have proved that r(10) = 32 and Michael
(surprisingly) that r(11) = 38 [Discrete and Computational Geometry (online 18 June Barnes
2018)]. See also A. Tiskin, Discrete Math. 307 (2007), 1973-1981, who showed among XCC problem
self-dual
other things that r(12) > 43, r(n) = Q(n1'534), r(n) = O(n2/(logn)1/15).] author
pinwheel
347. Fourteen proofs have been given by S. Wagon, AMM 94, (1987), 601-617. [For Miller
generalizations, see R. J. Bower and T. S. Michael, Math. Magazine 79 (2006), 14-30.] Perfect Packing
348. See F. W. Barnes’s complete solution, Discrete Mathematics 133 (1994), 55-78.
349. Let t = s/4. Each brick of an m-brick packing contains at least one of the 27 “spe
cial points” {(it, jt, kt) | 0 < i,j,k < 4}, because a, b, and c exceed t. Hence m < 27.
In a packing with m = 27, each of the “special lines” l*j-k, li-tk, lij-t with two
coordinates fixed will be totally full, because the bricks collectively occupy 27(a + b+ c)
units of space on those lines. The special lines also intersect the bricks in 27 segments
of each length a, b, c; hence each special line has a segment of each length.
Thus we’re led to solve an XCC problem with primary items pijk, l*jk, li*k, lij*
and secondary items xjk, yjk, zjk, and with options like ‘pijk xjk :ni yjk:n zijk:n3’
and ‘litk yi1k:n1 yi2k:n2 yi3k:n3’, where П1П2П3 is a permutation of {a,b,c}. That
problem has 7712 solutions, when we fix one of the six options for p111.
Only 168 of those solutions, in 21 equivalence classes under the 48 symmetries
of the cube, actually pack properly when (a, b, c) = (2, 3, 4). And it can be shown
that those 21 solutions will solve Hoffman’s problem for arbitrary (a, b, c). Here, for
example, is the unique solution that is “self-dual” —isomorphic to itself when a о c:
Types (i), (ii), (iii) contribute 6+10+4 nonisomorphic solutions. [George Miller’s puzzle
with bricks of tricolored faces is called Perfect Packing, because 28 is a perfect number.]
July 26, 2019
7.2.2.1 answers to exercises 219
351. (Generalizing exercise 349, Hoffman observed that such a construction would Hoffman
yield a nice geometrical way to prove the inequality (abode)1/5 < (a + b + c + d + e)/5.) arithmetic/geometric mean inequality
hypersolid pentominoes
352. None. But any eleven of the “hypersolid pentominoes” can easily be squeezed in; Lou
patent
QXWW. TSSSU SSZRU QQQQ. is one way to row and column sums
for example, XXXWW TTT.U ZZZRR OOOOO Hadamard transform
. XPPW TPPPU ZYRRU YYYY.
pack all but V. polyjubes
Sicherman
353. There are exactly 9 (including a mirror pair). They pack a 3 x 3 x 3 cube in edge-connected cubes
48 • 8789 ways,, such as 123 876. . , .
000 | 424 | 788. [See J. Lou, Danish patent 126840 (1973).]
567
354. (a) Let cell (x, y) of a polyomino correspond to (-x, x, y, -y). Let cell (x, y) of a
polyhex, as represented in exercise 315, correspond to (0, x, y, -x - y).
(b) A polysphere is planar if and only if the differences between its adjacent cells
lie in a plane. Each of those differences has the form eij = ei - ej , where e1 = (1, 0, 0, 0),
. . . , e4 = (0, 0, 0, 1). Three such differences can’t be linearly independent yet lie in a
plane; the linearly dependent cases are polyominoes and/or polyhexes.
(c) Every connected graph has at least one vertex whose removal doesn’t discon
nect the graph. So the result follows by induction on n.
(d) An orthogonal matrix fixes w + x + y + z if and only if its row and column
sums are 1. The matrices (i) T and (ii) R below respectively rotate by 120° about
x = y = z and by 90° about (x = y) Л (w = z).
,10 00 01 0,0 1i , 11 -1111,
1 -1 2 ,00 00 01 1,0 । , 5 -1 -1 3,
1 -1 -1 5 3
T= 0 0 0 1 ; R= -1 1 1 1 ; R = 0 1 0 0 ; H = -1 5 -1 3 .
0100 2 1 1 -1 1 1000 6 3 3 3 -3
(e) The matrices (i) R2 and (ii) H above respectively rotate by 180° about
(x = y) Л (w = z) and about (x = y) Л (w = 3z - 2x). Thus H can be used when z = 0.
(f) Suppose V' = {v1 ,...,v'n} is a rotation of V = {v1,...,vn} C S, where
Vk = (wk,xk,yk,zk), vkT = (wk,x'k,yk,zk)T = QvT, V1 = v1 = (0, 0, 0, 0), and
v2 = e12 = (1, -1, 0, 0). The matrix Q = (qij) is orthogonal, with row and column
sums and determinant 1. By applying an even permutation to the coordinates of v'
and the rows of Q, we can assume without loss of generality that v'2 = e12 = v2. Hence
qk1 = qk2 + 6k1 - Sk2, qu = q22. If Q = I we have Vp - Vq = eij = eiji = v, - vq for some
p, q, i, j, i, and j, with i < j. By orthogonality, e12 • eij = e12 • ei/j G {-1, 0, +1}.
If e12 • eij = 1, there are six cases, depending on (i,j,i/,j/): (1, 3,1,4) implies
Q = TH; (1, 4, 1, 3) implies Q = HT2; (1, 3, 4, 2) implies Q = T2RT or THR3T2;
(1, 4, 3, 2) implies Q = T2RT or HR; (1, 3, 3, 2) and (1, 4, 4, 2) are impossible.
If e12 • eij = 0, we have (i, j,/, j') = (3,4,4, 3) and Q is forced to be TR. Finally,
the case (i, j, i , j ) or e12 • eij = -1 is the same as the case (i, j, j , i ) or e12 • eij = +1.
Note: Some authors represent S as the set of integer triples (X, Y, Z) with
X +Y + Z even. The Hadamard transform provides an isomorphism between these rep
resentations: If -2M is the upper left 4 x 4 submatrix of 7.2.1.1-(2i), we have M2 = I,
det M = 1, and M takes (-x - y - z, x, y, z) ^ (0, x + z, y + z, x + y) = (0, X, Y, Z).
355. (a) Normalize the given polysphere by subtracting (xmin, ymin, zmin), to get its
base placement. Then, for each base placement P , form up to three others until
no more can be formed: (i) Replace each xyz by yzx. (ii) Replace each xyz by
(x + y + z)(t - z)(t - x), for some large t; then normalize. (iii) If z = 0 in each
cell of P, replace each xy0 by yx0.
[The (X, Y, Z) representation mentioned in answer 354 suggests “polyjubes” —
George Sicherman’s name for the sets of edge-connected cubes that don’t touch face-to-
face. Transformation (iii) does not apply to polyjubes; hence there are 5 trijubes and
July 26, 2019
220 ANSWERS TO EXERCISES 7.2.2.1
28 tetrajubes. Polyjubes are also equivalent to “polyrhons” —the connected sets of polyrhons
rhombic dodecahedra, which are the Voronoi regions of the face-centered cubic lattice. rhombic dodecahedra
Voronoi regions
See S. Coffin, The Puzzling World of Polyhedral Dissection (1990), Figure 167.] Coffin
(b) Phenalene has eight base placements; in lexicographic order they are {000, 001, lexicographic order
tetrahedron
010}, {000, 001, 100}, {000, 010, 100}, {001, 010, 011}, {001, 010, 100}, {001, 100, 101}, Takizawa
{010, 100, 110}, {011, 101, 110}. The straight trisphere has six base placements, namely Sillke
Wiezorke
{000, 001, 002}, {000, 010, 020}, {000, 100, 200}, {002, 011, 020}, {002, 101, 200}, {020, Bell
110, 200}. The bent trisphere has twelve, from {001, 010, 101} to {011, 100, 110}. And simplex
phenanthrene has twenty-four, from {000, 001, 011} to {020, 101, 110}.
(c) There are 853 connected subsets, with 475 different base placements. (Each
placement with max(x + y + z) = (1, 2, 3) occurs respectively (10, 4, 1) times.) They
form 25 distinct tetraspheres — five from tetrominoes and six additional planar pieces
from tetrahexes, plus four nonplanar nonchiral pieces and five chiral pairs:
j 48, 48) n 24, 24) o 12, 48) p 48, 120) u 24, 60)
000 001 002 012 000 001 011 000 001
012 000 001
010 011 002 010 000 001 011 020
C (12, 12) Д D (24, 24) GEL E (24, 60) F (12, 12) G (24, 60)
GJ Gr
000 001 101 111 001 010 101 102 W 000 001 101 110 00 002 010102000 001 010110
Each piece has been given an identifying letter. This chart shows the number of base
placements and the number of occurrences in simplex (3, 3, 3, 3, 3, 0, 0), as well as the
lexicographically smallest base placement. Notice that j and p have 48 base placements,
while a polycube can have at most 48. Piece s is simplex (1, 1, 1, 1, 1, 0, 0), a tetrahedron
with four equidistant spheres. Piece x is perhaps the most fascinating to play with.
[The tetraspheres were first enumerated by K. Takizawa; then T. Sillke enumer
ated the nonplanar polyspheres of larger sizes. See B. Wiezorke, Cubism For Fun 25,
part 3 (1990), 10-17; G. Bell, Cubism For Fun 81 (2010), 18-23; OEIS A038174.]
356. (a) The n-tetrahedron, which is the same as simplex(n — 1,n — 1,n — 1,n — 1,
n — 1, 0, 0), has base placement {xyz | x,y,z > 0, x + y + z < n}; (n+2) cells. (It has one
other base placement, namely {(n—1—x)(n—1 —y)(n—1 —z) | x,y,z > 0, x+y+z < n}.)
One of the 12 base placements of the m x n roof is {x(y+k)(m—1—y) | k > 0,
0 < x < n — k, 0 < y < m — k}. If m < n, it has m(m + 1)(3n — m + 1)/6 cells.
The stretched m x n roof is based on slicing the face-centered cubic lattice into
layers with constant y — z. (Each cell has two neighbors on its own layer, four neighbors
on each adjacent layer, and two neighbors that are two layers away.) One of its 12 base
placements is {(x+m—1—y)(y+k)y | k > 0, 0 < x < n — k, 0 < y < m — k}.
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 221
(b) Let’s call the four shapes T4, R3x4 , S3x4 , and S4x3 . Here are the stats: Bell
Pyradox
Total All planar Mixed All nonplanar propeller
Shape multiplicity
multisets(sets) (balanced) (balanced) (chiral) (balanced) (chiral) symmetry removal
T4 2952(1211) 174(34) 308(115) 2442(1062) 2(0) 26(0) Schneider
Gordon
R3x4 11531(6274) 372(69) 1250(583) 9818(5608) 3(0) 88(14) Becker
S3x4 1184(480) 51(6) 108(48) 1014(426) 1(0) 10(0) Pyramystery
Hein
S4x3 266(52) 2(0) 27(8) 234(44) 1(0) 2(0)
Soma
For example, {j, j, p, p, t} is one of 174 multisets of five planar pieces that can make T4.
[In fact, the solution is unique — and {j,j,p,p, t} also uniquely solves R3x4 and S3x4!
G. Bell used this fact as the basis for his elegant Triple Pyradox puzzle; see Cubism For
Fun 94 (2014), 10-13.] Of those 174 cases, 34 have five different pieces; for instance,
{n, o, p, u, y} is one of only seven that contains y, the “propeller.”
Many other suitable sets of five mix planar places with nonplanar ones. Of
these, 115 (like {g, G, i, s, x}) are closed under reflection; that one has 24 solutions, all
essentially the same. The other 1062 form 531 mirror-image pairs (like {d, e, f, G, i}
and {D, E, F, g, i}); every solution for a chiral set has 12 equivalents, not 24.
Algorithm M discovers all such solutions quickly, if we assign multiplicity [0 . . 5]
to each piece. There are respectively (88927, 77783, 3440, 996) solutions to (T4, R3x4,
S3x4, S4x3), without symmetry removal; they’re found in (840, 607, 48, 13) Мд.
Six of the multisets — three mirror pairs — are actually able to make all four
shapes. These versatile combinations of pieces are {e, g, g, p, p} and {E, G, G, p, p},
{g,j,p,p,p} and {G,j,p,p,p}, {g,p,p,p,p} and {G,p,p,p,p}.
There’s an obvious, yet interesting, way to make T4 with the “pure” multiset
{s, s, s, s, s}. The only other pure multiset that works is {p, p, p, p, p}, which is able to
form both T4 and R3x4 , as well as many other shapes noted by W. Schneider in 1995.
[A 2 x 7 roof also has 20 cells. So we might want to consider additional stats:
The long and skinny S7x2 can be made in only two ways, both with x in the middle,
surrounded by g’s or G’s. The set {i, j, n, o, p} packs both S2x7 and S7x2 , as well as T4.]
(c) Let’s name the trispheres 1, 2, 3, 4, according to the squared distance between
the two farthest-apart cells; thus the pieces in exercise 355 are 2, 4, 1, 3. The pyramid
P4 is buildable from 296 such multisets, many of which allow huge numbers of solutions.
(For example, each of the ten multisets that contain {1, 1, 2, 2, 3, 3, 4, 4} leads to more
than 30,000 solutions; {1, 1, 2, 2, 2, 3, 3, 4, 4, 4} has more than 120,000!) Most interesting
are the cases with unique solution ({2, 2, 4, 4, 4, 4, 4, 4, 4, 4}|, {1, 1, 1, 4, 4, 4, 4,
4, 4, 4}, {1, 2, 2, 2, 2, 2, 2, 2, 2, 2}), or with just two solutions ({2, 2, 2, 2, 2, 2, 2,
2, 2, 2}f, {1, 1, 3, 3, 3, 3, 3, 3, 3, 3}, {2, 4, 4, 4, 4, 4, 4, 4, 4, 4}ф); f = noted by
L. Gordon (1986); | = noted by J. Becker (2009). The stretched pyramid S4 has 213
such multisets, all of which can also make P4. Unique solutions occur for {1, 1, 1, 3,
4, 4, 4, 4, 4, 4} and {1, 3, 3, 3, 3, 3, 3, 3, 4, 4}; almost for {3, 3, 3, 3, 3, 3, 3, 3, 4, 4}.
Historical notes: The first polysphere puzzle may have been “Pyramystery,” copy
right by Piet Hein in 1967 when his Soma cube was becoming popular. Pyramystery
had the six pieces {1, 1, 3, 4, o, p}; Hein knew that it could form T4, as well as two
copies of T3 , and several planar designs. A similar puzzle of unknown origin, called
July 26, 2019
222 ANSWERS TO EXERCISES 7.2.2.1
Kugelpyramide, may have been created earlier, because it was seen by B. Wiezorke Kugelpyramide
in 1968. Kugelpyramide’s pieces, {1, 3, 4, 4, o, p} were slightly different. With either Wiezorke
Tetra
Pyramystery or Kugelpyramide one can make T4, T3 + T3, R3x4, R2x7, and S2x7; Kuwagaki
and with the not-thought-of pieces {1, 2, 3,4, o, p}, one could have made also S3x4 but Takenaka
Patent
not T3 + T3 . The first puzzle to mix polyomino-type polyspheres with polyhex-type octahedron
polyspheres — a nonobvious possibility — was Tetra, by A. Kuwagaki and S. Takenaka; Gordon
see Sugaku Seminar 11, 7 (July 1972), cover, 34-38; also U.S. Patent 3837652 (1974). WARP-30
Kadon Enterprises
That patent describes making P3 from the dispheres and trispheres, and making the 44- Voronoi
ball octahedron P4P3R from the planar tetraspheres {i, j, l, n, o, p, q, t, u, y, z}. In those body-centered cubic lattice
early days, the stretched roofs and pyramids weren’t known to be possible; they were face-centered cubic lattice
chiral pairs
first introduced by Leonard Gordon, in his WARP-30 puzzle (Kadon Enterprises, 1986). Owen
(d) The unique base placement is {xyz | x,y,z 6 {0,1, 2, 3},x = y = z = x}. Richards
Base placements
Stats are 95(0): 5(0) 13(0) 70(0) 3(0) 4(0). Only pieces a, c, d, q, u will fit in this polycrunches
shape. Here’s how to make it with {a, a, c, d, u, u}, {c, c, c, C, C, C}, or {u, u, u, u, u, u}: Sicherman
triagonal neighbors
a2 a2 a1 a2 a1 a1 C2c3 C2 c3 C2c3 u5u3 u1 u2 u3u3 trihexaspheres
c a2 c u2 a1u1 C2 c3 c1 C3 C2c3 u5 u6 u1 u6 u2u2 Bell
d d c u2 c u1 ; C1c2 c1 C3 c1 C3; u5u5 u1 u6 u1 u6 face-centered cubic lattice
d d d u2 u1u1 C1c2 C1 c2 C1c2 u4u4 u4 u6 u4u2
(Note that {q, q, q, q, q, q} is trivial.) This is a hollow object that can’t stand on its own.
357. Truncated octahedra are the Voronoi regions of the “body-centered cubic lattice,”
which is less tight than the face-centered cubic lattice: It can be represented as the set of
all integer triples (x, y, z) with x mod 2 = y mod 2 = z mod 2. Two truncated octahedra
whose centers are two such points are adjacent if and only the distance between those
points is either 3 (eight neighbors, joined at hexagonal faces) or 2 (six neighbors,
joined at square faces). There are 2 displatts, 6 trisplatts, and 44 tetrasplatts —
including 9 chiral pairs. [See M. Owen and M. Richards, Eureka 47 (1987), 53-58.]
Base placements can be found almost as in exercise 324, except that we must set
(x, y, z) ^ (y, 2fxmax] — x, z). Furthermore, each base placement should be normalized,
by adding (±1, ±1, ±1) if needed, so that xmin + ymin + zmin < 1.
[One might also consider truncating further, leaving only the union of four small
hexagonal prisms between diametrically opposite hexagonal faces. This yields a sub
family of polysplatts called “polycrunches” — named and enumerated by G. Sicherman:
Adjacent crunches, with centers 3 apart, are pasted together where the prisms meet.
The polycrunch family has 1 monocrunch, 1 dicrunch, 3 tricrunches, and 14 tetra
crunches (including 2 chiral pairs). The tricrunches have respectively (4, 12, 12) base
placements; the tetracrunches have respectively (4, 6, 6, 8, 12, 12, 12, 12, 24, . . . , 24).]
358. This fascinating packing is considerably more difficult than the other. For ex
ample, there are six distinct trihexaspheres, having respective angles of (60°, 90°,
arccos(—1/3) « 109.5°, 120°, arccos(—5/6) « 146.4°, 180°) and respective maximum
squared distances (1, 2, 8/3, 3, 11/3, 4). G. Bell has discovered a convenient way to rep
resent magnified polyhexaspheres within the face-centered cubic lattice: Consider the
subset S of S whose elements have the special form aj+вк+Yl for integers j, k, l, where
a = (0, 3, — 3, 0), в = (0, 0, 3, — 3), Y21 = (6l, — 2l, — 2l, — 2l), and Y21+1 = (6l + 3, — 3 — 2l,
—2l, —2l). Two cells of S are called adjacent if the distance between them is ^18.
Thus each cell v of layer l has six neighbors v ± {(0, 3, —3, 0), (0, 0, 3, —3), (0, —3, 0, 3)}
on the same level; three neighbors v + A[l even] + B[l odd] on level l + 1, where
A = {(3, —3, 0, 0), (3, 0, —3, 0), (3, 0, 0, —3)} and B = {(3, 1, —2, —2), (3, —2, 1, —2),
(3, —2, —2, 1)}; and three neighbors v — A[l odd] — B[l even] on level l — 1.
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 223
All of the tetraspheres are tetrahexaspheres, because they fit on at most two X pentomino
levels. But many of the pentaspheres, for example the planar one for pentomino T, are Bloch
not pentahexaspheres. A polyomino polyhexasphere exists if and only if the polyomino
fits in a 2xk box: Connected subsets of {(0, 0, 3k, -3k), (-3, -1, 2+3k, 2 —3k)} are OK.
The matrices T and R2HR2 of answer 354 are rotations of S. Therefore we can
obtain equivalent base placements in the manner of answer 355, replacing each xyz by
either yzx or (y + 32 w)(x + 23 w)(z + 32 w), where w = -x - y - z. Normalize a placement
by adding or subtracting 666 or 330 or 033 or 303. But the analysis is still incomplete:
Are further transformations of base placements needed? How many n-hexaspheres are
possible, for n = 4, 5, ... ? [See Cubism For Fun 106 (2018), 24-29.]
359. First we realize that every edge of the square must touch at least three pieces;
hence the pieces must in fact form a 3 x 3 arrangement. Consequently any correct
placement would also lead to a placement for nine pieces of sizes (17 - k) x (20 - k),
. . . , (24 - k) x (25 - k), into a (65 - 3k) x (65 - 3k) box. Unfortunately, however, if
we try, say, k = 16, Algorithm X quickly gives a contradiction.
But aha — a closer look shows that the pieces have rounded corners. Indeed,
there’s just enough room for pieces to get close enough together so that, if they truly
were rectangles, they’d make a 1 x 1 overlap at a corner.
So we can take k = 13 and make nine pieces of sizes 4 x 7, . . . , 11 x 12, consisting
of rectangles minus their corners. Those pieces can be packed into a 26 x 26 square, as if
they were polyominoes (see exercise 266), but with the individual cells of the enclosing
rectangle treated as secondary items because they needn’t be covered. (Well, the eight
cells adjacent to corners can be primary.) We can save a factor of 8 by insisting that
the 9 x 11 piece appear in the upper left quarter, with its long side horizontal.
Algorithm X solves that problem in 620 gigamems — but it finds 43 solutions,
most of which are unusable, because the missing corners give too much flexibility. The
unique correct solution is easily identified, because a 1 x 1 overlap between rectangles
in one place must be compensated by a 1 x 1 empty cell between rectangles in another.
The resulting cross pattern (like the X pentomino) occurs in just one of the 43.
360. Let there be mn primary items pj for 0 < i < m and 0 < j < n, one for
each cell that should be covered exactly once. Also introduce m primary items xi for
0 < i < m, as well as n primary items yj- for 0 < j < n. The exact cover problem has
(mJ1) • (nJ1) options, one for each subrectangle [a.. b) x [c.. d) with 0 < a < b < m
and 0 < c < d < n. The option for that subrectangle contains 2 + (b - a)(d - c) items,
namely xa , yc, and pij for a < i < b, c < j < d. The solutions correspond to reduced
decompositions when we insist that each xi be covered [1 . . n] times and that each yj
be covered [1 . . m] times. (We can save a little time by omitting x0 and y0.)
The 3 x 5 problem has 20165 solutions, found in 18 My. They include respectively
(1071, 3816, 5940, 5266, 2874, 976, 199, 22, 1) cases with (7, 8, . . . , 15) subrectangles.
[See C. J. Bloch, Environment and Planning B6 (1979), 155-190, for a complete
catalog of all reduced decompositions into at most seven subrectangles.]
361. The minimum is m + n - 1. Proof (by induction): The result is obvious when
m = 1 or n =1. Otherwise, given a decomposition into t subrectangles, k > 1 of them
must be confined to the nth column. If two of those k are contiguous, we can combine
them; the resulting dissection of order t - 1 reduces to either (m - 1) x n or m x n,
hence t - 1 > (m - 1) + n - 1. On the other hand if none of them are contiguous, the
reduction of the first n - 1 columns is m x (n - 1); hence t > m + (n - 1) - 1 + k.
July 26, 2019
224 answers to exercises 7.2.2.1
Close examination of this proof shows that a reduced decomposition has minimum tatami condition
order t if and only if its boundary edges form m - 1 horizontal lines and n - 1 vertical Earl
Scherer
lines that don’t cross each other. (In particular, the “tatami condition” is satisfied; see Graham
exercise 7.1.4-215.) See C. F. Earl, Environment and Planning B5 (1978), 179-187.
362. Simply remove the offending subrectangles, so that the cover problem has only
((m"1) —1)(("+1) -1) options. Now there are 13731 3x5 solutions, found in 11 M^, and
(410, 1974, 3830, 3968, 2432, 900, 194, 22, 1) cases with (7, 8, . . . , 15) subrectangles.
363. Introduce additional primary items Xi for 0 < i < m, to be covered [1 . . n - 1]
times, as well as Yj for 0 < j < n, to be covered [1 . . m - 1] times. Then add items Xi
for a < i < b and Yj for c < j < d to the constraint for subrectangle [a . . b) x [c . . d).
Now the 3 x 5 problem has just 216 solutions, found in 1.9 megamems. They
include (66, 106, 44) instances with (7, 8, 9) subrectangles. Just two of the solutions
are symmetric under left-right reflection, muriely and its top-bottom reflection.
364. We can delete non-tromino options from the exact cover problem, thereby getting
all faultfree tromino tilings that are reduced. If we also delete the constraints on xi
and yj — and if we require Xi and Yj to be covered [1 . . n] and [1 . . m] times instead of
[1 . . n - 1] and [1 . . m - 1] — we obtain all of the m x n faultfree tromino tilings.
It is known that such nontrivial tilings exist if and only if m,n > 7 and mn is a
multiple of 3. [See K. Scherer, JRM 13 (1980), 4-6; R. L. Graham, The Mathematical
Gardner (1981), 120-126.] So we look at the smallest cases in order of
mn: When (m, n) = (7, 9), (8, 9), (9, 9), (7, 12), (9, 10), we get respectively
(32, 32), (48, 48), (16, 16), (706, 1026), (1080, 1336) solutions. Hence the
assertion is false; a smallest counterexample is shown.
365. Augment the exact cover problem of answer 362 by introducing m2"1 + n"2 1 - 2
secondary items xab and ycd, for 0 < a < b < m and 0 < c < d < n, (a,b) = (0,m),
(c, d) = (0, n). Include item xab and ycd in the option for subrectangle [a . . b) x [c . . d).
Furthermore, cover xi [1 . . m - i] times, not [1 . . n]; cover yj [1 . . n - j] times.
366. The hint follows because [a . . b) x [0 . . d) cannot coexist motleywise with its left
right reflection [a . . b) x [n-d . . n). Thus we can forbid half of the solutions.
Consider, for example, the case (m, n) = (7, 7). Every solution will include x67
with some ycd. If it’s y46 , say, left-right reflection would produce an equivalent solution
with y13 ; therefore we disallow the option (a, b, c, d) = (6, 7, 4, 6). Similarly, we disallow
(a, b, c, d) = (6, 7, c, d) whenever 7 - d < c.
Reflection doesn’t change the bottom-row rectangle when c+d = 7, so we haven’t
broken all the symmetry. But we can complete the job by looking also at the top-row
rectangle, namely the option where x01 occurs with some ycidi. Let’s introduce new
secondary items t1, t2, t3, and include tc in the option that has x67 with yc(7-c). Then
we include t1, t2, and t3 in the option that has x01 with yc/d/ for c + d > 7. We also
add t1 to the option with x01 and y25 ; and we add both t1 and t2 to the option with
x01 and y34. This works beautifully, because no solution can have c = c and d = d.
In general, we introduce new secondary items tc for 1 < c < n/2, and we disallow
all options x(m-1)m ycd for which c + d > n. We put tc into the option that contains
x(m-1)m Уc(n-c); t1 thru tL(n-1)/2J into the option that contains x01 yc/d/ when c + d >
n; and t1 thru tc/-1 into the option that contains x01 yc'(n-c'). (Think about it.)
For example, when m = n = 7 there now are 717 options instead of 729, 57
secondary items instead of 54. We now find 352546 solutions after only 13.2 gigamems
of computation, instead of 705092 solutions after 26.4. The search tree now has just
7.8 meganodes instead of 15.7.
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 225
(It’s tempting to believe that the same idea will break top-bottom symmetry too. faultfree
But that would be fallacious: Once we’ve fixed attention on the bottommost row while Postl
nested motley dissections
breaking left-right symmetry, we’ve lost all symmetry between top and bottom.) pinwheel
367. From any m x n dissection of order t we get two (m+2) x (n+2) dissections of
order t + 4, by enclosing it within two 1 x (m+1) tiles and two 1 x (n+1) tiles. So
the claim follows by induction and the examples in exercise 365, together with a 5 x 6
example of order 10 — of which there are 8 symmetrical instances such as the n—rr
one shown here. (This construction is faultfree, and it’s also “tight”: The order
of every m x n dissection is at least m + n — 1, by exercise 361.)
In general, Helmut Postl observes that we can create nested motley dissections
by motley-dissecting any subrectangle of a motley dissection (taking care not to repeat
any internal boundary coordinates) and reducing the result. For example, one of
the 2 • (6 + 3 + 3 + 3 + 1 + 9 + 3) =56 ways to nest a pinwheel within the second X F
motley 4 x 4 is shown here. —
368. The number of subrectangles [a . . b) x [c . . d) that have either c = k or d = k,
given k, is > 2 when k G {0, n} and > 3 when 0 < k < n. Hence 2t > 2 + 3(n — 1) + 2.
369. All 214 of the 5x7 motley dissections have order 11, which is far short of
2 — 1 = 14; and there are no 5x8s, 5x9s, or 5x10s. Surprisingly, however,
6
424 of the 696 dissections of size 6x12 do have the optimum order 20,
and 7x17 dissections with the optimum order 27 also exist. Examples of
these remarkable patterns are shown. (The case m = 7 is still not fully
explored except for small n. For example, the total number of motley
7x17 dissections is unknown. No 7x18s exist, by exercise 368. If we
restrict attention to symmetrical dissections, the maximum orders
for 5 < m < 8 are 11 (5x7); 19 (6x11); 25 (7x15); 33 (8x21).)
370. The basic idea is to combine complementary options into a single option whenever
possible. More precisely: (i) If a + b = m and c + d = n, we retain the option as usual;
it is self-complementary. (ii) Otherwise, if a + b = m or c + d = n, reject the option;
merging would be non-motley. (iii) Otherwise, if a + b > m, reject the option; we’ve
already considered its complement. (iv) Otherwise, if b = 1 and c + d < n, reject
the option; its complement is illegal. (v) Otherwise, if b > m/2 and c < n/2 and
d > n/2, reject the option; it intersects its complement. (vi) Otherwise merge the
option with its complement. For example, when (m, n) = (4, 5), case (i) arises when
(a, b, c, d) = (1, 3, 2, 3); the option is ‘x1 y2 p12 p22 x13 y23 ’ as in answer 366. Case
(ii) arises when (a, b, c, d) = (1, 3, 0, 1). Case (iii) arises when (a, b) = (2, 3). Case (iv)
arises when (a, b, c, d) = (0, 1, 0, 1); the complement (3, 4, 4, 5) isn’t a valid subrectangle
in answer 366. Case (v) arises when (a, b, c, d) = (1, 3, 1, 3); cells p22 and p23 occur also
in the complement (1, 3, 2, 4). And case (vi) arises when (a, b, c, d) = (0, 1, 4, 5); the
merged option is the union of ‘x0 y4 p04 x01 y45 t1 t2 ’ and ‘x3 y0 p30 x34 y01 ’. (Well,
x0 and y0 are actually omitted, as suggested in answer 360.)
Size 8 x 16 has (6703, 1984, 10132, 1621, 47) solutions, of orders (26, . . . , 30).
371. (a) Again we merge compatible options, as in answer 370. But now (a, b,c, d) ^
(c, d,n — b, n — a) ^ (n — b, n — c, n — b, n — a) ^ (n — b, n — a, c, d), so we typically must
merge four options instead of two. The rules are: Reject if a = n — 1 and c + d > n,
or c = n — 1 and a + b < n, or b = 1 and c + d < n, or d = 1 and a + b > n. Also reject
if (a, b, c, d) is lexicographically greater than any of its three successors. But accept,
without merging, if (a, b, c, d) = (c, d, n—b, n—a). Otherwise reject ifb > c and b+d > n,
July 26, 2019
226 answers to exercises 7.2.2.1
or if b > n/2 and c < n/2 and d > n/2, because of intersection. Also reject if a + b = n
or c + d = n, because of the motley condition. Otherwise merge four options into one.
For example, the merged option when n = 4 and (a, b, c, d) = (0, 1, 2, 4) is ‘x0 y2
p02 p03 x01 y24 t1 x2 y3 p23 p33 x24 y34 x3 y0 p30 p31 x34 y24 p00 p10 x02 y01’, except
that x0 and y0 are omitted. Notice that it’s imp ortant not to include an item xi or yj
twice, when merging in cases that have a = c or b = d or a = n - d or b = n - c.
(b) With bidiagonal symmetry it’s possible to have (a, b, c, d) = (c, d, a, b) but
(a, b, c, d) = (n - d, n - c, n - b, n - a), or vice versa. Thus we’ll sometimes merge two
options, we’ll sometimes merge four, and we’ll sometimes accept without merging. In
detail: Reject if a = n - 1 and c + d > n, or c = n - 1 and a + b > n, or b = 1 and
c + d < n, or d = 1 and a + b < n. Also reject if (a, b, c, d) is lexicographically greater
than any of its three successors. But accept, without merging, if a = c = n - d = n - b.
Otherwise reject if b > c or b > n - d or a + b = n or c + d = n. Otherwise merge two
or four distinct options into one.
Examples when n = 4 are: ‘x1 y1 p11 p12 p21 p22 x13 y13’; ‘x0 y3 p03 x01 y34 t1
x3 y0 p30 x34 y01 ’; ‘x0 y2 p02 x34 y23 t1 x1 y3 p13 x12 y34 x3 y1 p31 x34 y12 x2 y0 p20
x23 y01 ’; again with x0 and y0 suppressed.
(c) The unique solution for n = 10 is shown. [The total number of such i
patterns for n = (10, 11, ... , 16) turns out to be (1, 0, 3, 6, 28, 20, 354). All -r
354 of the 16 x 16 solutions are found in only 560 megamems; they have orders —
34, 36, and 38-44. Furthermore the number of n x n motley dissections with — -
symmetry (a), for n = (3, 4, 5, . . . , 16), turns out to be (1, 0, 2, 2, 8, 18, 66, 220, 1024,
4178, 21890, 102351, 598756, 3275503), respectively. Algorithm M needs 3.3 teramems
when n = 16; those patterns have orders 4k and 4k + 1 for k = 8, 9, . . . , 13.]
372. (a) The r = n + 1 rows of B contain r +’s and r -’s; hence each vertex of H has
in-degree 1 and out-degree 1. By connectedness, H must be an oriented r-cycle, Cf‘.
(b) Now n = r - m = 2; the n + 1 rows of B must be ±{11100, 00111, 11011}.
(c) Proceed in two stages: First find all vectors orthogonal to A; then choose
n + 1 of them. For example, given the A for *KJ , there are options ‘#j xj:+’, ‘#j xj:0’,
‘#j Xj:-’, for 0 < j < 6. Then there are options such as ‘0 x0:+ x3:0 x5:-’, ‘0 x0:0
X3:- X5:-’, . . . , for the ways to be orthogonal to row 0 of A; and so on. (A row with 3
nonzero entries leads to 7 such options; a row with 4 nonzero entries leads to 19; etc.)
In the second stage, use all the nonzero solutions to the first stage to define an
exact cover problem with corresponding options. The idea is to cover Pj and Nj for
0 < j < r, where the option corresponding to a solution has Pj for all j with Xj:+ and
Nj for all j with Xj :-. We also insert the special item # into each option, and give it
multiplicity n + 1, so that exactly n + 1 options will be chosen. For example, the option
that corresponds to the solution with X0:+, X1:+, X2:0, X3:-, X4:0, X5:0 is ‘# P0 P1 N3’.
Discard any solutions to the second stage that don’t define a connected digraph.
(d) Stage 1 of the method outlined in (c) creates an XCC problem with 15 + 10
items and 125 options; it has 219 solutions, one of which has all Xj:0. Stage 2 creates an
MCC problem with 21 items and 218 options. Unfortunately it has no solutions that in
volve n+1 = 7 options. (It does have 195 solutions that involve 6; but they don’t count.)
(e) Suppose horizontal segment i touches vertical segment j. Then j lies on
opposite sides of two subrectangles, both above i or both below i. Hence exactly zero
or two terms of every ai • bj are nonzero, and the signs cancel when there are two. (The
same construction works when four subrectangles meet at a point, if we simply split
either the horizontal segment or the vertical segment into two pieces at that point.)
July 26, 2019
7.2.2.1 answers to exercises 227
Notes: This theory was introduced by N. Biggs, Proc. Cambridge Phil. Soc. 65 Biggs
(1969), 399-408, who also proved considerably more. For example, since AAT is the Laplacian matrix
spanning trees
Laplacian matrix of G, he was able to show that orthogonal digraphs G and H always planar
have the same number of spanning trees (see exercise 7.2.1.6-104). If G is planar, and dual graph
three-connected
has no vertices of degree 1, it is orthogonal to its dual graph H, because we can rotate pinwheel
the direction of each edge by 90° after interchanging the roles of vertices and faces. factored
A single graph G might have many nonisomorphic orthogonal mates. (Consider, backtrack
van Hertog
for example, ^УУ^.) But uniqueness might be provable if G is three-connected. No Gardner
examples of nonplanar graphs with orthogonal mates are known. Cutler
strict
373. The reduction of a perfectly decomposed rectangle is a motley dissection. Thus
we can find all perfectly decomposed rectangles by “unreducing” all motley dissections.
For example, the only motley dissection of order 5 is the 3 x 3 pinwheel. Thus
the perfectly decomposed m x n rectangles of order 5 with integer dimensions are the
positive integer solutions to x1 + x2 + x3 = m, y1 + y2 + y3 = n such that the ten values
x1, x2, x3, x1 + x2, x2 + x3, y1, y2, y3, y1 + y2, y2 + y3 are distinct. Those equations
are readily factored into two easy backtrack problems, one for m and one for n, each
producing a list of five-element sets {x1 , x2, x3, x1 + x2, x2 + x3}; then we search for
all pairs of disjoint solutions to the two subproblems. In this way we quickly see that
the equations have just two essentially different solutions when m = n = 11, namely
(x1, x2, x3) = (1, 7, 3) and (y1 , y2, y3) = (2, 4, 5) or (5, 4, 2). The smallest perfectly
decomposed squares of order 5 therefore have size 11 x 11, and there are two of them
(shown below); they were discovered by M. van Hertog, who reported them to Martin
Gardner in May 1979. (Incidentally, a 12 x 12 square can also be perfectly decomposed.)
There are no solutions of order 6. Those of orders 7, 8, 9, 10 must come
respectively from motley dissections of sizes 4 x 4, 4 x 5, 5 x 5, and 5 x 6. By looking
at them all, we find that the smallest n x n squares respectively have n = 18, 21,
24, and 28. Each of the order-t solutions shown here uses rectangles of dimensions
{1, 2, . . . , 2t}, except in the case t = 9: There’s a unique perfectly decomposed 24 x 24
square of order 9, and it uses the dimensions {1, 2, . . . , 17, 19}.
(b) False (but close). If the reduced rectangle is m x n, one of its subrectangles
might be1 x n or m x 1; a motley dissection must be strict.
b
(c) True. Label the rectangles {a, b, c, d, e} as shown. Then there’s a e----a < c
' d
contradiction: wb > wd ^^ we > wc ^^ he < hc ^^ hd < hb ^^ wb < wd.
(d) The order can’t be 6, because the reduction would then have to be a
pinwheel together with a 1 x 3 subrectangle, and the argument in (c) would still
apply. Thus the order must be 7, and we must show that the second dissection
of exercise 365 doesn’t work. Labeling its regions {a, . . . , g} as shown, we have hd > ha;
hence wa > wd. Also he > hb; so wb > we. Oops: wf > wg and hf > hg.
July 26, 2019
228 ANSWERS TO EXERCISES 7.2.2.1
therefore h4 > h5, h4 > h6, h6 > h7, w4 > w3, w3 > w1, w4 > w2. Now h5 < h6 ^^
W5 > W6 ^^ W2 > W3 ^^ h2 < кз ^^ h& + h,7 < hg. Hence h,5 < h& implies hg > h-6;
we must have h5 > h6 , thus also h2 > h3. Finally h2 < h1, because h7 < h5 .
(e) The condition is clearly necessary. Conversely, given any such pair of solutions,
the rectangles w1 x ah1, ... , wt x aht are incomparable for all large enough a.
[Many questions remain unanswered: Is it NP-hard to determine whether or
not a given motley dissection supports an incomparable dissection? Is there a motley
dissection that supports incomparable dissections having two different permutation
labels? Can a symmetric motley dissection ever support an incomparable dissection?]
375. (a) By exercise 374(d), the widths and heights must satisfy
w5 = w2 + w4, w6 = w3 + w4, w7 = w1 + w3 + w4 ;
h3 = h4 + h5, h2 = h4 + h6 + h7, h1 = h4 + h5 + h6.
To prove the hint, consider answer 374(a). Each Zj for 1 < j < t can be either h or w;
then z2t+1-j is the opposite. So there are 2t ways to shuffle the h’s and w’s together.
For example, suppose all the h’s come first, namely h7 < • • • < h1 < w1 < • • • < w7:
1 < h7, h7 + 1 < h6, h6 + 1 < h5, h5 + 1 < h4, h4 + 1 < h4 + h5,
h4 + h5 + 1 < h4 + h6 + h7 , h4 + h6 + h7 + 1 < h4 + h5 + h6 ,
h4 + h5 + h6 < w1 , w1 + 1 < w2 , w2 + 1 < w3, w3 + 1 < w4 ,
w4 + 1 < w2 + w4 , w2 + w4 + 1 < w3 + w4 , w3 + w4 + 1 < w1 + w3 + w4.
For each of these four choices there are 256 easy subproblems to consider. The best integer programming
perimeters are respectively (44, 44, 44, 56); the best square sizes are respectively — Yao
Reingold
and surprisingly — (27, 36, 35, 35). [With eight subrectangles we can dissect a sig Sands
nificantly smaller square than we can with seven! Furthermore, no smaller square Jepsen
Nuij
can be incomparably dissected, integerwise, because nine subrectangles would be too
many.] One way to achieve perimeter 44 is with (w1, w2 , w3, w4, w5, h8, h7, h6, h4) =
(4, 5, 6, 7, 8, 1, 2, 3, 8) in the third diagram. The only way to achieve a square of side 27
is with (w1, w2, w3, w4, w5, h8, h7, h6, h4) = (1, 3, 5, 7, 11, 4, 6, 8, 9) in the first diagram.
These linear programs usually have integer solutions; but sometimes they don’t.
For example, the optimum perimeter for the second diagram in the case h8 < h7 < w1 <
h6 < w2 < w3 < w4 < h5 turns out to be 97/2, achievable when (w1 , w2, w3, w4, w5 , h8,
h7, h6, h4) = (7, 11, 13, 15, 17, 3, 5, 9, 17)/2. The minimum rises to 52, if we restrict to
integer solutions, achieved by (w1, w2, w3, w4, w5, h8, h7, h6, h4) = (4, 6, 7, 8, 9, 1, 3, 5, 9).
[The theory of incomparable dissections was developed by A. C. C. Yao, E. M.
Reingold, and B. Sands in JRM 8 (1976), 112-119. For generalizations to three
dimensions, see C. H. Jepsen, Mathematics Magazine 59 (1986), 283-292.]
376. This is an incomparable dissection in which exercise 374(d) applies. Let’s try first
to solve the equations a(x+y+z) = bx = c(w+x) = d(w+x+y) = (a+b)w = (b+c)y =
(b+c+d)z = 1, by setting b = x = 1. We find successively c = 1/(w+1), a = (1 - w)/w,
y = (w + 1)/(w + 2), d = (w + 1)/(w(w + 2)), z = (w + 1)(w + 3)/((w + 2)(w + 4)).
Therefore x + y + z - 1/a = (2w + 3)(2w2+ 6w - 5)/((w - 1)(w + 2)(w + 4)), and we must
have 2w2+6w = 5. The positive root of this quadratic is w = (V — 3)/2, where V = \/19.
Having decomposed the rectangle (a+b+c+d) x (w+x+y+ z) into seven different
rectangles of area 1, we normalize it, dividing (a, b, c, d) by a + b + c + d =
175(V + 1) and dividing (w, x, y, z) by w+x+y+z = 5(V — 1). This gives the -------- p
desired tiling (shown), with rectangles of dimensions -4(7 — V) x -5(7 + V),
4255f(1+
- -|1 ।I A x --5fi(1 W),
. )v
V)x - (—1 + V),
x -J ) x --5CQ
i A 2-5 3 53 , -2-fc(8 Av
-(7+V)x - (7—V).
'.8 iI . A), -2-(84)
fQ i Av
x --5fft(8 A), —----
-/
42 -5 , -4 -5
[See W. A. A. Nuij, AMM 81 (1974), 665-666. To get eight different rectangles
of area 1/8, we can shrink one dimension by 7/8 and attach a rectangle (1/8) x 1.
Then to get nine of area 1/9, we can shrink the other dimension by 8/9 and attach a
(1/9) x 1 sliver. And so on. The eight-rectangle problem also has two other solutions,
supported by the third and fourth 4 x 5 patterns in exercise 375(b).]
377. (a) We can obtain h x w except when w is odd and h is not a multiple of 3. For
if w is even, we can concatenate w/2 instances of size h x 2; if h is a multiple of 3, we
can concatenate h/3 instances of size 3 x w; otherwise we can’t use concatenation to
obtain w as the sum of two even numbers, or h as the sum of two multiples of 3.
(b) The shapes 2x3, 2x4, 2x5, 3x4, 3x5, 3x6, 3x7 are necessary and sufficient.
(And then Л(5) = {hxw | h > 1,w > 3} U {2hx3 | h > 1}.)
(c) S = {2x4, 3x8, 4x2, 8x3}.
(d) hxw G S if and only if h = an7 for some a with [m/n'J < a < 2|_m/n/J + 2
and w = bn" for some b with [m/n"J < b < 2|_m/n//J + 2, where n' = n/ gcd(n, w) and
n" = n/ gcd(n, h).
element of B such that qr mod b = r, for 0 < r < b, or let qr be undefined if no such de Bruijn
element exists. Then every element of B is some qr plus a multiple of q0 = b. Klarner
Reid
Therefore in two dimensions, there’s a finite set X = {h1xw1,... ,htxwt} C T Marshall
such that the width of every element of T is in Л(Х *), where X * = {w1,... ,wt} is the Reid
Bitner
set of widths in X . Let p = h1 . . . ht be the product of all heights in X . It follows that frontier
pxw G Л(Х) whenever hxw G T. Sillke
For 0 < r < p, let Tr be the elements hxw of T with h mod p = r, and let Qr be Fogel
Goldenberg
a finite subset of Tr such that every element of Tr has a width in Л(ф*). Let q be the Liu
largest height of any element of any Qr . Notice that if hxw G T with h > q, and if Kelly
h'xw' G Qh mod p, we have hxw' G Л(Х U Qr), because pxw' G Л(Х) and h — h' is a basis
positive multiple of p. Hence hxw G Л({йк w' | h'xw' G Qr}) C Л(Х U Qr).
Finally, for 1 < i < q, let T/ be the elements hxw of T with h = i, and let Pi be
a finite subset of T such that every element of Ti’ has a width in Л(Р/‘). Then every
element of T belongs to Л(Х U Q0 U • • • U Qp-1 U P1 U • • • U Pq).
[This argument extends to any number of dimensions. See N. G. de Bruijn
and D. A. Klarner, Philips Research Reports 30 (1975), 337*-343*; Michael Reid,
J. Combinatorial Theory A111 (2005), 89-105.]
379. A 2x5 packing is obvious; thus the basis contains 2x5 (and 5x2). The case 5xw
and w > 2 has a packing only if hx(w — 2) does. The case h = 3 is clearly impossible.
The case h = 7 is more interesting: 7x10 follows by concatenation, while 7x15
has 80 distinct and easily found solutions. Hence the basis contains 7x15 and 15x7.
This basis is complete: We’ve shown that if h is not a multiple of 5, hxw is
possible whenever w is a multiple of 5, except when h = 1 or h = 3 or (h = 5 and w
is odd) or (h is odd and w = 5). If h and w are both multiples of 5, hxw is possible
except when h or w equals 5 and the other is odd. [See W. R. Marshall, J. Comb.
Theory A77 (1997), 181-192; M. Reid, J. Comb. Theory A80 (1997), 106-123.]
380. The minimum basis consists of 15x15 (see Fig. 73) plus 39 pairs {hxw, wxh},
where (h, w) G {(5, 10), (9, 20), (9, 30), (9, 45), (9, 55), (10, 14), (10, 16), (10, 23),
(10, 27), (11, 20), (11, 30), (11, 35), (11, 45), (12, 50), (12, 55), (12, 60), (12, 65), (12, 70),
(12, 75), (12, 80), (12, 85), (12, 90), (12, 95), (13, 20), (13, 30), (13, 35), (13, 45), (14, 15),
(15,16), (15,17), (15,19), (15,21), (15,22), (15,23), (17,20), (17,25), (18,25), (18,35),
(22, 25)}. (This problem has a long history, going back to the discovery by David
Klarner that ten one-sided Y pentominoes can be packed uniquely in a 5 x 10 box
[Fibonacci Quarterly 3 (1965), 20]. Klarner eventually found 14 of the 39 basic pairs
by hand, including the difficult case (12, 80). The other nine cases (12, w) were found
by J. Bitner [JRM 7 (1974), 276-278], using a frontier-transition method that works
much faster than Algorithm X in cases where h is much less than w. The complete set
was nailed down by T. Sillke in 1992 [unpublished], then independently by J. Fogel, M.
Goldenberg, and A. Liu [Mathematics and Informatics Quarterly 11 (2001), 133-137].)
381. Algorithm X quickly finds examples for n = 7, 11, 12, 13, 15, 16, 17; hence it’s
possible for all n > 11. [J. B. Kelly discovered the case n = 7 in AMM 73 (1966), 468.
Are all packable rectangles consequences of this basis?]
382. Let the back corner in the illustration be the point 777, and write just ‘abcdef ’
instead of [a . . b)x[c . . d)x[e . . f). The subcuboids are 670517 (270601) 176705 (012706)
051767 (060127), 561547 (260312) 475615 (122603) 154756 (031226), 351446 (361324)
463514 (243613) 144635 (132436), 575757 (020202), 454545 (232323) — with the 11
mirror images in parentheses — plus the central cubie 343434. Notice that each of the 28
possible intervals is used in each dimension, except [0 . . 4), [1 . . 6), [2 . . 5), [3 . . 7), [0 . . 7).
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 231
I started from a central cube and built outwards, all the while Hilbert
staring at the 24-cell in Hilbert’s Geometry and the Imagination. KIM
Gardner
— SCOTT KIM, letter to Martin Gardner (December 1975) Postl
puzzle
383. (Solution by Helmut Postl.) We can use the 7-tuples (2, 10, 27, 17, 11, 20, 5), Postl
(1, 14, 18, 8, 21, 24, 6), (3, 19, 16, 7, 34, 9, 4) to “unreduce” the 1st, 2nd, 3rd coordinates. author
For example, subcuboid 670517 becomes 5 x (1+14+18+8+21) x (19+16+7+34+9+4). Cutler
Kim
The resulting dissection, into blocks of sizes 1x70x87, 2x77x88, 3x80x86, 4x67x91,
5x 62x 89, 6x 79x 90, 7x 8x 17, 9x 51 x 65, 10x 38x 71, 11 x 21 x 34, 12x 15x 22,
13 x 25 x 30, 14 x 39 x 66, 16 x 18 x 27, 19 x 33 x 75, 20 x 47 x 61, 23 x 32 x 48,
24x 36 x 76, 26x 37x 50, 28x40x43, 29 x 31 x42, 35 x44x 53, 41 x 45x 54, makes a
fiendishly difficult puzzle.
How were those magic 7-tuples discovered? An exhaustive search such as that of
exercise 374 was out of the question. Postl first looked for 7-tuples that led to very few
dimensions in the “popular” ranges [13 . . 23] and [29 . . 39]. With luck, a large set of
other 7-tuples would lead to no conflict in the 23 relevant subtotals; and with further
luck, some of those wouldn’t conflict with each other.
(Postl also proved that no 91 x 91 x 91 decomposition is possible.)
384. The exact cover problem of answer 365 is readily extended to 3D: The option for
every admissible subcuboid [a . . b) x [c . . d) x [e . . f) has 6 + (b - a)(d - c)(f - e) items,
namely xa yc ze xab ycd zef and the cells pijk that are covered.
We can do somewhat better, as in exercise 366: Most of the improvement in that
answer can be achieved also 3Dwise, if we simply omit cases where a = l - 1 and either
c + d > m or e + f > n. Furthermore, if m = n we can omit cases with (e, f) < (c, d).
Without those omissions, Algorithm M handles the case l = m = n = 7 in 98
teramems, producing 2432 solutions. With them, the running time is reduced to 43
teramems, and 397 solutions are found.
(The 7 x 7 x 7 problem can be factored into subproblems, based on the patterns
that appear on the cube’s six visible faces. These patterns reduce to 5 x 5 pinwheels,
and it takes only about 40 ,\l// to discover all 152 possibilities. Furthermore, those
possibilities reduce to only 5 cases, under the 48 symmetries of a cube. Each of those
cases can then be solved by embedding the 5 x 5 reduced patterns into 7 x 7 unreduced
patterns, considering 153 = 3375 possibilities for the three faces adjacent to vertex 000.
Most of those possibilities are immediately ruled out. Hence each of the five cases can be
solved by Algorithm C in about 70 G// — making the total running time about 350 G//.
However, this 120-fold increase in speed cost the author two man-days of work.)
All three methods showed that, up to isomorphism, exactly 56 distinct motley
cubes of size 7 x 7 x 7 are possible. Each of those 56 dissections has exactly 23 cuboids.
Nine of them are symmetric under the mapping xyz ^ (7 — x)(7 — y)(7 — z); and one
of those nine, namely the one in exercise 382, has six automorphisms.
[These runs confirm and slightly extend the work of W. H. Cutler in JRM 12
(1979), 104-111. His computer program found exactly 56 distinct possibilities, when
restricting the search to solutions that have exactly 23 cuboids.]
385. No; there are infinitely many. For example, Postl has constructed a primitive
11 x 11 x 13 by pasting Kim’s 7 x 7 x 7 to its mirror image, perturbing a few planes
normal to the splice, and reducing.
386. The twelve possible symmetries can be represented as the permutations of {0, 1, 2,
3, 4, 5} defined by x ^ (ax + b) mod 6, where a = ±1 and 0 < b < 6; let’s denote that
permutation by b or b, according to the sign of a. There are ten symmetry classes,
July 26, 2019
232 ANSWERS TO EXERCISES 7.2.2.1
depending on the automorphisms that are present: (i) all twelve; (ii) {0, 0, 2, 2, 4, 4}; automorphisms
(iii) {0,1,2,3,4,5}; (iv) {0,1,2,3,4,5}; (v) {0,3,0,3} or {0,3,2,5} or {0, 3, 4, 1}; (vi) biaxial
triaxial
{0, 2, 4}; (vii) {0, 3}; (viii) {0, 0} or {0, 2} or {0, 4}; (ix){0,1}or{0,3}or{0,5}; (x) {0}. axial
60°
(i) (ii) (iii) (iv) (v) (vi) (vii) (viii) (ix) (x) 120°
180°
O; a;
0^;z
full triaxial-a triaxial-b 60°
;
biaxial
;
120°
^^;
180°
;
axial-a axial-b
D;
none
base placements
signed permutations
rotation
bent tricube
L-twist
(i) (ii) (iii) (iv) (v) (vi) (vii) (viii) (ix) (x) subgroups
o; Л; ; ci ; СЭ; ;
ЧЪ; 64; »; .
BDD
Boolean function
binary operator
groupoid, see binop
full triaxial-a triaxial-b 60° biaxial 120° 180° axial-a axial-b none magma, see binop
conjugate
(Types (ii), (iii) and (viii), (ix) depend on whether a reflection is left-right or top-down. symmetry types
Notice that there are 12/k base placements when there are k automorphisms.) even
biaxial symmetry
387. The 24 potential symmetries S can be represented as signed permutations of central symmetry
{±1, ±2, ±3}, meaning that coordinates are permuted and/or complemented. Using
the notation of answer 7.2.1.2-20, they are 123, 123, 123, ... , 321, where the number
of inversions of the permutation plus the number of complementations is even.
Each of those symmetries is a rotation in 3-space about some line through the
origin. (After a polycube has been rotated by one of its symmetries, we should shift
the result, if necessary, to bring it into the original position.) For example, 132 takes
(x,y,z) ^ (c — x,z,y); it’s a rotation of 180° about the diagonal line x = c/2, y = z.
It’s a symmetry of the bent tricube {000, 001, 010} when c = 0; it’s a symmetry of the
L-twist {000, 001, 100, 110} when c = 1.
All subgroups of this group are easily found by constructing the BDD for the
Boolean function whose 24 variables are the potential symmetries. Indeed, all subsets
of any set S that are closed under any given binary operator * on that set are the
solutions to Дx yeS(—x V —y V (x * y)). In this case the resulting BDD (found in
2.5 M^) has 197 nodes, and it characterizes exactly 30 subgroups.
Two subgroups T and T' are said to be conjugate if T' = t-Tt for some t G S.
Such subgroups are considered to be equivalent, because they amount to viewing the
objects from a different direction. The distinct conjugacy classes of subgroups according
to this equivalence relation are called the “symmetry types,” and there are 11 of them:
(i) (ii) (iii) (iv) (v) (vi) (vii) (viii) (ix) (x) (xi)
®;
®; ®W; W
full even 8-fold 6-fold 90° bidiagonal tricentral 120° diagonal axial none
Class (ii) consists of the 12 symmetries whose permutations are even. The smallest
polycube which admits these symmetries and no more — and hence it has just two base
placements — contains 20 cubies, with 12 surrounding a central core of 8. Class (iv)
has one symmetry for each permutation of the three coordinates. Classes (iii), (v), (vi),
(vii), (ix), (x), (xi) correspond to the eight symmetry types of a square, with reflections
implemented by “turning the square over” to the opposite side. In this interpretation
biaxial symmetry becomes “tricentral,” because it corresponds to central symmetry
about each coordinate axis. The former class called “180°” is now the same as “axial,”
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 233
when viewed from either of the two other axes. [Many of these twelve examples have re hyperoctahedral symmetries
flective symmetries too; but those don’t count. Under the full set of 48 hyperoctahedral Lunnon
polyhexes
symmetries, when reflections are allowed, there are 33 symmetry types(!), nicely pre hidden singles
sented by W. F. Lunnon in Graph Theory and Computing (Academic Press, 1972), naked single
Historical note
101-108. Lunnon also exhibited the ten symmetry types for polyhexes on pages 87-100.] Asao
388. The directed path of four weak clues in (a) is equivalent to the five strong clues Dainarism
Nikoli
(1, 2, 3, 4, 5). Then there are “hidden singles” in columns 1 and 2, leading to a “naked digraph
single” in cell (4, 2), etc.; we cruise to victory without branching. Puzzle (b) has a out-degree d+ (v)
naked single in (4, 2) — and we notice, by the way, that the middle cell needn’t be 5 stack
Euler
even though it is greater than each of its four neighbors. Then (4, 4) is naked, and so
on; again everything is forced. Puzzle (c) begins with hidden singles, which place the
three missing 1s and then the 5 in row 0. After we fix cell (4, 2), the rest falls into place.
4 [5] [1 [3 [2 3> 1 [4 [5] [2] [3 И [1 [2]<[4
5 > 4 M > 4 [з 2 И [1 [4 [5 4 Ш И [3 [2
9 (1782), 85-239, §148], though he was nearly blind at the time.] Every 5 x 5 latin string
square has 40 pairs of adjacent elements, leading to a string of 40 inequality signs; and sort
self-dual
we can sort those 161280 strings. Only 115262 distinct strings actually occur; and only transposition
82148 of them occur just once. The other 79132 cannot be identified by weak clues only. Bell numbers
Wn the nth Bell number
392. Here are the first examples found of each type, and the total number of cases: restricted growth strings
(More detailed counting shows exactly (369404, 2976, 4216, 3584, . . . , 80) cases with at
least one long path and (0, 1, 2, 3, . . . , 1344) solutions; (405636, 4000, 4400, 1888, . . . ,
72) cases with no long path and (0, 1, 2, 3, . . . , 24128) solutions.) Example (i) below is
one way to get the maximum number of solutions, using six particularly unhelpful clues.
The most interesting cases, of course, are those that make valid puzzles. They
fall into equivalence classes under rotation and/or reflection and/or complementation;
thus sixteen examples are typically equivalent to any given one. However, there are 46
equivalence classes with only eight members, self-dual under transposition, of which 26
have long paths (as in (ii), (iii), (iv) below) and 18 do not (as in (v), (vi), (vii)). Thus
(173+26)+(241+18) = 458 essentially different futoshiki puzzles with six weak clues are
valid; however, many of these are really the same, under row-and-column permutations
that preserve all clues. The most difficult symmetric instance is probably (vii), because
exercise 390 needs a 374-node search tree to solve it. (A clever solver will, however,
deduce immediately that all diagonal elements of a symmetric puzzle must be 3!)
□<□ □ □ □ □ □ □ □<□ □>□ □ □ □ □□□□ □ □ □ □ □>□ □>□ □ □ □ □>□ □ □ □
□>□<□ □ □ □ □ □□□ □ □□□ □ □ □<□<□ □ □ □ □□□ □□□□ □ □ □<□ □ □
□□□□ □ □ □ □□□ □ □□□ □ □<□ □ □ □ □ □ □□□ □ □<□ □ □ □□□□ □
□□□□ □ □ □ □ □<□ □ □□□ □ □□□□ □ □ □ □<□>□ □□□□ □ □□□□ □
□□□□ □ □ □ □<□ □ □ □ □<□<□ □□□□ □ □ □ □□□ □ □<□ □ □ □>□ □ □ □
(i) (ii) (iii) (iv) (v) (vi) (vii)
393. The 56 = 15625 ways to label six cells can be reduced to w6 = 203, by limiting
consideration to restricted growth strings (Section 7.2.1.5), multiplying the results for
every such string by 5k when it has k different labels. (In fact, only 202 such strings are
relevant, because the last one (123456) will be multiplied by 56 = 0 and never used.)
Running through each subset of five cells, we find respectively (1877807500, 864000, 0,
0, 1296000, 10368000, . . . , 144000) cases that have (0, 1, 2, 3, 4, 5, . . . , 336) solutions.
0 solutions 1 solution 4 solutions 5 solutions 336 solutions 336 solutions
ШШШШШ Ш12ППП Ш12ППП Ш12ППП Ш[2[3[4[5 И □ □ □ [2
□□□□□ □□□□□
□□□□□ □□□□□ □□□□□
Every case with a unique solution is obtained from the example shown by independently
permuting the rows, columns, and labels. (Indeed, 864000 = 5!3/2.)
July 26, 2019
7.2.2.1 answers to exercises 235
394. Let there be h strong clues and k = 5 - h weak clues. Four solutions are Katz
Bean
obtained only in (144, 2016, 2880) cases for h = (1, 2, 3). In every such case, two preprocessing
rows and two columns are completely free from clues; thus the four solutions arise from
swapping those two rows and/or those two columns. As in answer 392, most of the cases
belong to classes of 16 puzzles that are equivalent under rotation, transposition, and/or
complementation. But when h = 3 there are 30 classes of size 8, having transposition
symmetry (see (iii) and (iv) below); also 6 self-dual classes of size 8 (see (v)). Hence
there are 9 + 126 + (36 + 162) = 333 inequivalent 4-solution 5-clue futoshikis altogether.
и □ □ □ □ и □ □ □ □ И □<□ □ □ И □□ □ □ □ И □ □ □ □ □ □ □ □
□ □ □ □ □ □ □ [5 □ □ □ [5 □ □ □ (5 □ □ □ □ □ □ □<□ [3
□ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□ □ □ □ □ □ □ □ □ □>□ [5 □
□ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □□ □ □ □ □ □ □ □
□<□<□<□ □ и □<□<□
□<□<□ □<□<□ [2 □ □
□<□ □ □<□<□ □ [6 □
□ □<□<□ □<□ □ □ [5
be 1. For example, the topmost sheep has only three options in the example puzzles, author
namely ‘s03 x03:1 x04:b x13:c x02:d’, where b + c + d = 1. Olson
Henle
This XCC problem for the rightmost example puzzle has five solutions: historical note
Miyamoto
Yano
Nikoli
historical note
XCC problem
To eliminate the spurious ones, we traverse the fence from ‘+’ to ‘-’, accepting a backtrack
solution only if that path contains all of the color transitions between adjacent cells. bit vectors
queens problem
(b) There’s a unique solution if we put k sheep into a diagonal of length k; but that A
puzzle is trivial, not “interesting.” Random trials show that about one configuration in p
every 10,000 makes a suitable puzzle; the author found the first three examples below
in that way. The fourth example was contrived by hand. All are solvable by hand:
[E. Olson invented this game; see J. Henle, Math. Intelligencer 40,1 (2018), 69-70.]
398. The blanks in rows 0 and 4 of (c) can be filled with 3 and 5 in two ways.
3 14+ 15 X 34560 X 3 3 14+ 15 X
1 4 2 3 5 4 I 2 3 1 5 4 1 2
9X 2 5 9X 2 6+
3 1 5 2 4 3 1 5 4 2 1 3 5 2 4
6+ 5+ 10+ 5
a) 4 3 1 5 2 ; b) 5 3 4 2 1 c) 3 5 4 1 2
3 5+ 3+ 9+ 3 5+
2 5 4 1 3 3 4 1 5 3 5 2 3 4 1
5 7+ 2 1 8X 9+
5 2 3 4 1 1 5 2 3 4 2 4 1
(Incidentally, this formulation doesn’t require the cells of a cage to be connected.) prime implicants
monotone Boolean function
400. The formulation in answer 399 makes it easy to omit the options for any cage. dominoes
Thus Algorithm C almost instantaneously breezes through those 2048 problems, and author
preprocessing
finds that exactly 499 of them are uniquely solvable. The number of such puzzles with author
(5, 6, . . . , 11) given clues is (14, 103, 184, 134, 52, 11, 1); for example, one can solve it latin square
when given only the clues ‘15x’, ‘6+’, ‘3-’, ‘5+’, ‘5’, in five cages! Exactly (14, 41, 6)
of those 499 puzzles have (5, 6, 7) minimal clues; minimal-clue puzzles correspond to
the prime implicants of the associated monotone Boolean function.
Similar remarks apply to puzzle 398(b), which can be solved uniquely without
knowing either of the clues ‘34560x’ or ‘2’ — although the reader probably made heavy
use of those clues when solving it. (On the other hand, its clue ‘9+’ cannot be omitted.)
401. There are 36 ways to cover a 4 x 4 board with dominoes, but nearly all of them are
unsuitable. For example, Щ can’t define the cages of a valid kenken problem, because
the middle rows of any solution could be swapped to give another solution. And no
two dominoes can cover a 2 x 2 region whose solution has the form baab. Therefore we’re
left with only two cage patterns, g| and its transpose.
A given cage pattern can be filled with two clues of each type in 8!/2!4 = 2520
ways. Most of those ways are obviously impossible, because ^ cannot be applied to
the pairs {2, 3} or {3, 4}. It turns out that (1620, 847, 52, 1) of the cases give a kenken
puzzle with respectively (0, 1, 2, 4) solutions. Notable examples are
2+ 12X 2+ 12X
2+ 5+ 1— 2— 5+ 5+
2—
and 2—
12 X 3+ 12 X 2+
where the first is the “most difficult,” in the sense that its search tree via the construc
tion of exercise 399 has the most nodes (134). The second is the one with four solutions.
402. The solution follows answer 403. The author constructed this puzzle by first
designing the cages, then generating a dozen or so random latin squares via exercise 86
until finding one that had a unique solution. Then the domino clues were permuted at
random, ten times; the most difficult of those ten puzzles (77 meganodes) was selected.
The construction of answer 399 gives an XCC problem with 10914 options, 486 +
432 items, and 163288 total entries. There are respectively (720, 684, 744, 1310,
990, 360, 792, 708, 568, 1200, 606, 30) options for the pentominoes (O, P, . . . , Z);
preprocessing with Algorithm P reduces those counts to (600, 565, 96, 1122, 852,
248, 744, 656, 568, 1144, 606, 26). Overall, the reduced problem has 8927 options,
484 + 432 items, and 134530 total entries. The total time to find the solution and
prove its uniqueness was 9 G// for Algorithm P and 293 G// for Algorithm C. (Without
preprocessing, Algorithm C would have taken 6.4 T^, and its search tree would have
had 2 giganodes. Could a human being solve this puzzle by hand?)
403. The author’s best attempt, shown below, manages to match 35 digits before
deviating in the final cage. The construction of answer 399 fails spectacularly on this
particular instance, because the monster cage for ‘79+’ has 3,978,616,320 options! We
can, however, work around that problem by simply making row 7 unconstrained and
subtracting 1 + 2 + • • • + 9 = 45 from the cage total. (A latin square is determined by any
n — 1 of its rows.) Then Algorithm C solves the problem handily, with a cost of 2 G//
(from 184422 options), and with a search tree of only 252 nodes. (See Appendix E.
July 26, 2019
238 ANSWERS TO EXERCISES 7.2.2.1
Surprisingly, the non-п clue ‘3780x’ in the bottom row affects row 1 of the solution.) Hamiltonian cycle
simple path
O P 2+ Q Benedek
3+ 14 X 15 X 9 + 2+ 6+
B
15+
A 7
11+
6 2
1
4 9 5 3
1
8 1 C
Pm x Pn
7 8 9 2 5 1 C A 6 3 4 B 5+ 35 + 8 9+
3 8+ 16+ 1 T
2 1 8 9 6 C 4 3 7 B 5 A
R 5+ S 21+ 8+ 7+ 9 32X
5 4 6 7 A 2 B 8 C 9 3 1
1- 7 V 3- 84X 62 + 64 X
3 2 A B 7 6 1 9 5 4 C 8
4+ 15+ 11+ 4 W
1 5 B 4 C 7 8 2 9 6 A 3 3
3+ 8+ 8+ 4 2-
4 9 3 1 8 5 7 B A C 6 2 3 8+ 32 X 79 + 50X
U 13+ 16+ 7+ 1
C B 2 8 4 3 A 7 1 5 9 6
2+ 8+ 1 Y 2+ 2+
A 3 4 5 9 B 6 C 8 1 2 7
3 X 14+ Z 14+
9 6 C 3 B A 2 1 4
7 8 5
3 13+ 5+
6 7 1 C 3 8 5 4 2 A B 9 2- 8 3780 X
4
8 C 5
10+
A 1
3+
9 3 6 B 2 7 4 L_
404. Such puzzles can be defined on any N-vertex graph G, some of whose vertices are
labeled with elements of {1, 2, . . . , N}; the problem is to extend such a labeling to a full
Hamiltonian path, in all possible ways. We imagine an additional vertex to, which is
adjacent to all the others. A Hamiltonian path in G is then equivalent to a Hamiltonian
cycle in G U to, with to interposed between the first and last vertices of the path.
For 1 < k < N, let vk be the vertex labeled k, or vk = Л if there’s no such vertex.
Also let v0 = vN+1 = to. We define an XCC problem with two kinds of primary items:
(i) -v and +v for all unlabeled vertices v; (ii) sk for 0 < k < N, except when both
vk = Л and vk+1 = Л. We also introduce secondary items pv for all unlabeled v, and
qk for all unused labels k. (Thus the example has 35 primary items {-00, +00, -10,
+10, -11, . . . , +33, s1 , . . . , s7 , s9 , . . . , s16}, and 20 secondary items {p00 , . . . , p33 ,
q2 , q4, . . . , q15 , q16}.) The options for sk are ‘sk -u pu:k qk:u +v pv:k+1 qk+1:v’ for
all pairs of unlab eled vertices u --- v such that u might be labeled k and v might be
labeled k + 1. However, we omit -u pu:k qk :u if vk = Л, and we omit +v pv:k+1 qk+1 :v
if vk+1 = Л. For example, four of the options in the 4 x 4 toy problem are
‘s3 +10 p10:4 q4:10’, ‘s6 -31 p31:6 q6:31 +30 p30:7 q7:30’,
‘s4 -11 p11:4 q4:11’, ‘s6 -30 p30:6 q6:30 +31 p31:7 q7:31’;
the bottom two appear in the solution, but the top two do not. The secondary items
are colored so that interdependent options will always link up properly.
Suppose l < k < r and vl = Л, vl+1 = • • • = vk = • • • = vr-1 = Л, vr = Л. The
statement “u might be labeled k” in the specification ab ove means more precisely that
there is a simple path of length k - l from vl to u and a simple path of length r - k
from u to vr. (This condition is necessary for u to be labeled k, but not sufficient.
It is, however, sufficient for our purposes.) A simple path of length 1 is equivalent to
adjacency. A simple path of length > 1 can be decided using the algorithm in the
following exercise; but if that algorithm is taking too long, we can proceed safely by
assuming that a simple path does exist. The value of min(k - l, r - k) is usually small.
[Gyora Benedek invented Hidato® in 2005 and began to publish examples in
2008. Similar brainteasers sprang up later, based on other kinds of paths; but king
moves Pm x Pn have a special appeal because they can cross each other.]
405. For l = 0, 1, . . . , L, find the set Sl of all pairs (S, w) such that at least one simple
path from v to w runs through the vertices of S U v, where S is an l-element set. Clearly
S0 = {(0, v)}; and Sl+1 = {(S U w, w) | w — u and w / S for some (S, u) S Sl}.
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 239
If at most 58 vertices w are reachable from v in < l steps, we can represent each octabyte
pair (S, w) in a single octabyte, with 6 bits for w and 58 bits for S. These octabytes representation of sets
two stacks
can be stored in two stacks, alternately at the low and high ends of a sequential list. sequential list
smile
406. The moves from 12 to 19 are forced, as are those on several other diagonals. So pidato puzzle
everything is quickly filled in, except for blanks between 42 and 51. Aha. Hamiltonian king paths
ZDD
407. Using exercise 404, Algorithm C finds the 52 solutions quickly (1500 kilomems). Historical note
Only one of them has ‘18’ in row 3, column 3; and that clue makes a puzzle with a Nikoli
nicely symmetric solution (see Appendix E). [We could also put ‘27’ in cell (2, 4); or Kanamoto
Yada
‘18’ in (4, 3); or ‘17’ in (4, 4). But that would destroy the smile.] Yuzawa
swastika
408. 2 6 10 8-fold symmetry
1 5 9 Beluhov
(See Appendix E for solutions.
22 18 13
(a) Are the numbers 5 and 18 best
21 17 14
possible for 6 x 6?)
25 30 36
26 29 35
410. Puzzles (a), (b), (d) have unique solutions; remarkably, all 12 of the clues in (b)
are essential. But (c) has 40 solutions, including two whose loop doesn’t touch a corner.
'0 0 0 ЧГТ 1' X л A x x
'0 „0 1’ (d) 11; x x x
(a) A □
0
'.o'.;
~0
(b) :1 : 1;
i 3 E
(x) \ xi\
’xx'xx' '
X.
’0 0 0 ii i ii~ '3 A '3'
Pattern (x), incidentally, has unique solutions for x = 0, 1, 2, but none for x = 3.
[Historical note: Slitherlink was invented by Nikoli editor Nobuhiko Kanamoto,
who combined the puzzle ideas of Ayato Yada and Kazuyuki Yuzawa. See Puzzle
Communication Nikoli 26 (June 1989).]
411. False; for instance, -^ has two. [But such cases are somewhat mysterious. There
are 93 of size 5 x 5, including three that give two loops despite 8-fold symmetry. A
6 x 6 example yields four loops; can you find them? (See Appendix E.) Are three loops
possible? If m + 1 and n + 1 are relatively prime, N. Beluhov has proved that an m x n
slitherlink diagram with all clues given cannot have more than one solution.]
1 2 2 2 1 3 2 2 2 3 3 22 2 3
32'2'2'2'2
222232
2 10 12 2 1112 2 32 3 2 222222
2 0 0 0 2 2 10 12 2 20 2 2 222222
21'0'1'2 2 1112 23'2'3'2 23'2'2'22
1'2'2 21 '3'2'22'3' 32'2'2'3 22'2'2'23
412. With an m x n grid it’s convenient to use the (2m + 1)(2n + 1) pairs xy for
0 < x < 2m and 0 < y < 2n, with xy representing either (i) a vertex, if x and y are
July 26, 2019
240 answers to exercises 7.2.2.1
both even; (ii) a cell, if x and y are both odd; or (iii) an edge, if x + y is odd. The edge planar graph
between two adjacent vertices is their midpoint. The four edges surrounding a cell are face
fragment list
obtained by adding (±1, 0) and (0, ±1) to the coordinates of the cell. dancing slitherlinks
To obtain the weak solutions for any slitherlink diagram on a planar graph, preprocess
cutset
introduce one primary item for each vertex, one primary item for each face in which the
number of edges is specified, and one secondary item for each edge. There are 1 + d2
options for each vertex v of degree d, namely ‘v e1:x1 . .. ed:xd’ where xj G {0,1} and
x1 + • • • + xd = 0 or 2. There are (d) options for each face f of degree d that should have
k edges in the path, namely ‘f e1:x1 ... ed:xd’ with xj G {0,1} and x1 + • • • + xd = k.
For example, the options for vertex 00 in the diagram of exercise 410(i) are ‘00
01:1 10:1’ and ‘00 01:0 10:0’. The options for cell 11 are ‘11 01:1 10:1 12:1 21:0’, ‘11
01:1 10:1 12:0 21:1’, ‘11 01:1 10:0 12:1 21:1’, ‘11 01:0 10:1 12:1 21:1’.
This construction yields (2, 2, 104, 2) weak solutions for puzzles 410(a) to 410(d).
(In cases (a), (b), (d) we can delete or insert the 4-cycle that surrounds the middle cell.)
413. Let each record for an item include four new fields left, right, mate, exmate.
The left and right fields of the secondary item that represents edge u ---v will point
to the primary items u and v. The left, right, and mate fields of the primary item
that represents vertex v will represent v’s presence or absence in a doubly linked list
of endpoints called the “fragment list,” which contains the essential information about
all edges that currently have been selected.
For example, suppose three edges currently have color 1, say v1 --- v2 , v3 --- v4 ,
and v2 --- v5 . The fragment list will then contain the endpoints {v1 , v3 , v4 , v5 } of the
two path fragments v1 --- v2 --- v5 and v3 --- v4; we’ll also have mate(v1 ) = v5 ,
mate(v2) = -1, mate(v3) = v4, mate(v4) = v3, mate(v5) = v1. Other vertices v
will have mate(v) = 0, indicating their absence from any existing edges. When the
‘purify’ routine (55) is called to give color 1 to a new edge i, it will know that this
edge should not be chosen if left(i) = v1 and right(i) = v5 , say, or in general if
left(i) and right(i) are mates, because that would close a loop disjoint from the other
fragment. Furthermore, ‘purify’ won’t give color 1 to edge i if mate(left(i)) = -1, or
if mate(right(i)) = -1, or if the fragment list already contains a completed loop.
In this example, vertex v2 was deleted from the fragment list when edge v2 --- v5
was chosen, because v2 was no longer an endpoint. At that time, ‘purify’ not only
set MATE(v2) ^ -1, it also set EXMATE(v2) ^ v1, so that ‘unpurify’ would be able
to undo the operation later. Similarly, a subsequent edge v1 --- v4 will remove both
v1 and v4 from the fragment list, by using (1) with LEFT and RIGHT links, and by
setting EXMATE(vi) ^ MATE(vi), MATE(MATE(vi)) ^ MATE(v4), MATE(vi) 4----1, etc.
Of course the dancing-links trick (2) will eventually be used later, to undo deletion (1).
Caution: Algorithm P must be modified so that it never discards redundant
items, when it is used to preprocess a problem for this extension of Algorithm C.
414. After the forced moves have been made as shown, only two edges are
undecided between the vertices of rows 1 and 2. A strongest possible algorithm X
X
will know that those two edges must either both be present or both absent. X
(In fact, a truly strongest possible algorithm will force both to be present as X
two will force a relation between two undecided edges. An algorithm that dynamically minimum cutsets
maintains minimum cutsets of G (see Section 7.5.3) will therefore be helpful. max-flow, min-cut
ZDD
415. Instead of solving millions of puzzles, we can use the ZDD technology of Section simple cycles, enumerating
signature
7.1.4 to list all the loops in P6 P6, of which there are 1222363. Say that the “signature” projection vector
of a loop is the full sequence of 25 clues — the number of edges around each cell. It family of sets
turns out that 93 pairs of loops have the same signature (see exercise 411); those 186 p, the power set
nonsubsets f Z g
loops cannot be the solution to any 5 x 5 slitherlink puzzle. Let S be the set of 1222270 minimal elements of a family of sets
distinct signatures, and let S' be the subset of 1222177 that give a valid 25-clue puzzle. reachability algorithm
Beluhov
Suppose s G S has t > 0 entries equal to digit d; and ДОА1
21311
V22Z1
22111
for s G S let p(s, s ) be the binary “projection vector” xi ...xt, s = ^^Г/з^З, s = лмлз
, 1 t 110 1Г
where xk = 1 if and only if s has d in the kth cell where s has d.
,
23211
.1.2.1.12. .22.1.1.2
For example, if d = 1, the signatures s and s shown above have t = 10 and p(s,sz) =
1011101111. Form the set P(sz) = {p(s,sz) | s = sz}. Then s, with all clues restricted
to digit d, is a valid puzzle if and only if 11... 1 / P(sz). Moreover, the valid puzzles
contained in that one are precisely those whose projections aren’t contained in any
element of P(sz). (If we regard P(sz) as a family of sets, such projections are the
elements of p Z P(sz), in the notation of exercise 7.1.4-236.) We can find those vectors,
and the minimal ones, with a reachability algorithm such as Algorithm 7.1.3R.
In this way we discover exactly (9310695, 833269, 242772, 35940, 25) valid puzzles
for d = (0, 1, 2, 3, 4), of which exactly (27335, 227152, 11740, 17427, 25) have no
redundant clues. The minimum number of clues, in such irredundant homogeneous
puzzles, is respectively (7, 8, 11, 4, 1); and the maximum number is respectively (12,
14, 18, 10, 1). Many of the extreme cases make pleasant little puzzles:
0 000 1 111 2 22 3 3
’ ’0* ’0........................ 1’1 ’ ’f!’^ '2'2'2 2' ' ’22 22 ................... 3’ ■ ' ’3
0 0 0 11 11 22222222 3
' ' '0' ' ' '0' '0......................... 1’1 T ’1'1................. 2* ’ ,2,2,2,2,2 ■333 ’3’ ’ ' ’3
o’ V ’ ’ '0 '0 ’0..................... Г ’ T ’1 ’1............. 2’ ’ ’ '2' ’22 3.................... 3 ’3 ’3
(See Appendix E. This minimum-1s puzzle is one of two based on signature s above.)
416. Of course d = 4 is trivial. So is d = 0; but that case has an amusing sparse
construction. The following puzzles generalize to all n with (n + d) mod 4 = 1:
0 00000 3 333333333333
000 1111111111 2 2 2 2 2 2 2 2 2 2 3
O' ' ' '0' ' ' '0' ' ' '0' 1 11111111 1 3....................................................
2 2 2 2 2 2 2 2 2 2 2 3 333333333333
' ' '0' ' ' '0' ' ' '0' ' ' ГГ ТГГГ1ТГ '1
111 1111111 2 2 2 2 2 2 2 2 2 2 2 3
0 0 0 0 2 2 2 2 2 2 2 2 2 2
0 0 0 111 1111111 2 2 2 2 2 2 2 2 2 2 3 333333333333
0 0 0 0 11 1111111 1 2 2 2 2 2 2 2 2 2 2 3
11 1111111 1 3' ■3'3'3'33'3'3'3'33'3'3'
0 0 0 ГГГ ТГГ1ТГГ 2 2 2 2 2 2 2 2 2 2 2 3
O' ' ' ’0’ ■ ' ’0’ ■ ' '0' 2 2 2 2 2 2 2 2 2 2 2
' ' '0' ' ' '0' ' ' '0' ' ' ГГГ ТГГ1ТГГ 3 333333333333
11 1111111 1 2 2 2 2 2 2 2 2 2 2 2 3
0 0 0 0 2 2 2 2 2 2 2 2 2 2 2
0 0 0 1 11111111 1 2 2 2 2 2 2 2 2 2 2 2 3 333333333333
1111111111 3....................................................
0 0 0 0 ' ■3'3'3'3'33'3'3'3'33'3'3'
[See the solutions in Appendix E. N. Beluhov, who found these patterns for d = 2 and 3,
has raised interesting problems of optimum density: Let e(d) = lim inf n -v ||S||/n2 and
e(d) = liinsupn v ||S||/n2, where S ranges over all valid n x n slitherlink puzzles that
are d-homogeneous, and where ||S„ denotes the number of clues. Clearly ||S„ < n2/2
when d = 3, because no 2 x 2 subsquare can contain more than two 3s. Furthermore
||S|| > n2/4 — O(n) when d = 0. For we must eliminate at least n2 + 2n of the 2n(n + 1)
edges if all but one cycle is to be cut; each 0 eliminates at most four. If n > 5 we
obtain a valid puzzle with only fourteen 1s, by placing a suitable 4 x 6 pattern in
the upper left corner. Similarly, there’s a valid puzzle with only four 3s, if n > 3.
July 26, 2019
242 ANSWERS TO EXERCISES 7.2.2.1
ТГГ '1
Therefore these constructions prove that в(0) = в(1) = в(2) = 1; в(3) = 1/2; 1 1 SAT solvers
111 1 projection
в(1) = в(3) = в(4) = в(4) = 0; в(0) = 1/4. But в(2) remains unknown.] 1111
author
417. The pattern for d = 3 in answer 416 works also for d = 0, if we remove one clue preprocessing
Knuth
from the top row. Fascinating diagrams arise when such patterns are attempted for pi, as source
d = 1; Beluhov’s largest example so far is the 30 x 30 puzzle obtained when removing Beluhov
the 1 in column 26 of row 0. (Such puzzles are extremely difficult for the algorithm of
answer 413 to handle; but SAT solvers have no trouble with them.)
418. (a) 6 • 2612 ~ 5.7 x 1017, from the central cell and 12 complementary pairs.
(b,c,d,e) As in answer 415, we define the projection p(s,s') = x1 .. .x13, where
xk = 1 if and only if s and s' agree in the kth pair (or in the center, when k = 13).
We obtain altogether 2,692,250,947 puzzles, of which 199,470,026 are minimal. The
minimal ones include (1, 24, 0, 7, 42, 1648, 13428, 257105, . . . , 184, 8) that have
respectively (1, 2, 3, 4, 5, 6, 7, 8, . . . , 19, 20) clues; here are some choice specimens:
............................ 0................................. 0..................... 0 0 321 '3'
0..............................................010 132012122
' ' '4................................................................................ 0............................................. 113’23..................................... 22 '22'
.................................................................3 2'3 ■ '1 '3.......................... 23 0' T '21 ’22’
43 33.................................................... 3223
419. To design this puzzle, the author began with the signature of the desired loop (see
answer 415), then removed pairs of centrally opposite clues, more or less at random,
until no redundant pairs remained. The construction of exercise 412 produced 2267 op-
tions on 404+573 items from the final clue set; and Algorithm P
needed just 17 M^ to remove 1246 of those options. Then the
algorithm of exercise 413 discovered the solution, and proved
it unique, with 5.5 G/л of computation and a search tree of 15
meganodes. (It’s another big win for preprocessing: Otherwise
that algorithm would have taken 37 Tu, with a 78-giganode
search tree!) Reference: D. E. Knuth, Computer Modern Type
faces (Addison-Wesley, 1986), 158-159.
420. Suppose S is a solution (or even a weak solution). Mark with a
2 ,2 2 ,2.
black dot all vertices whose adjacent 2 includes exactly one edge of S
.2 ‘2 ~?2
touching that vertex, as in the 7 x 13 example illustrated. Let G be
'2 '2 '2 "2
the graph whose vertices form an (m + 3)/2 x (n + 3)/2 grid like the
'2 '2 ‘2 ~~2
white dots in this example, and whose edges connect adjacent white
dots that are not separated by black dots. Then the corner vertices of G have degree 1;
but all other white dots have even degree (possibly degree 4).
Consider the connected component C of G that contains the northwest corner.
It also contains another corner, because every graph has an even number of vertices of
odd degree. When n mod 4 = 1 it can’t be the northeast corner; when m mod 4 = 1 it
can’t be the southwest corner. So C must contain the southeast corner, if m mod 4 =
n mod 4=1. Similarly, there’s a connected component C' that contains the northeast
and southwest corners. But that’s impossible! All white dots of C have even parity;
all white dots of C' have odd parity; and they cannot cross.
[This exercise and proof are due to N. Beluhov. Conversely, the 7 x 13 example
[Historical note: Masyu was invented by Tatsuo Yano, who developed a white- Historical note
circles-only version, together with Mitsuhiro Ase, who contributed the black circles. Yano
Ase
See Puzzle Communication Nikoli 84 (April 1999); 89 (March 2000).] equivalence algorithm
union-find algorithm
422. Now we use the (2m — 1)(2n — 1) pairs xy for 0 < x < 2m — 2 and 0 < y < 2n — 2. signature
Cell (i, j) corresponds to x = 2i and y = 2j (a “vertex”); clue (i, j) corresponds to x =
2i + 1 and y = 2j + 1. Edges are as before, and we use the same options to ensure that
either 0 or 2 edges touch every vertex in a solution. The only essential change from an
swer 412 is the treatment of clues, since masyu clues are different from slitherlink clues.
A black masyu clue in (i, j) has four options, corresponding to north-west, north
east, south-west, and south-east legs; for example, the north-west option is ‘C (i, j)
N(i, j):1 NN(i, j):1 W (i, j):1 W W (i, j):1’, where C(i, j) = (2i+1)(2j+1), N(i, j) =
C(i, j) —10, NN(i, j) = C(i,j) — 30, W(i,j) = C(i,j) — 01, WW(i,j) = C(i,j) — 03.
Edges off the grid have “color” 0, so this option is omitted when i < 1 or j < 1.
A white masyu clue in (i, j) has six options, three for north-south orientation and
three for east-west. The three for east-west are ‘C(i, j) E(i, j):1 EE(i, j):0 W (i, j):1
W W (i, j):0’, ‘C(i, j) E(i, j):1 EE(i, j):0 W (i, j):1 W W (i, j):1’, and ‘C(i, j) E(i, j):1
EE(i, j):1 W (i, j):1 WW (i, j):0’. Again we omit an option that would set an off-board
edge to 1. An off-board edge item that sets color 0 is silently dropped.
For example, the options for the black clue in exercise 421’s puzzle are ‘15 14:1 34:1
03:1 01:1’, ‘15 14:1 34:1 05:1 07:1’. The options for the white clue in the bottom row are
‘97 87:1 85:1 83:0’, ‘97 87:1 85:1 83:1’. That puzzle has 15 clue options altogether, and
119 vertex options ‘00 01:1 10:1’, ‘00 01:0 10:0’, ‘02 01:1 03:1 12:0’, . . . , ‘88 78:0 87:0’.
423. Obtain a representative of each class of equivalent variables, for example by adapt
ing Algorithm 2.3.3E. This calculation may show that certain variables are constant.
A contradiction might also arise — for example, if there’s a white clue in a corner; in
such cases the masyu puzzle has no solution.
The vertex options of answer 422 can now be eliminated, at all vertices for which
a clue was given. The clue options can also be consolidated, so that equivalent variables
don’t appear together, and so that constants are suppressed. Every option that tries
to set a variable both true and false is, of course, eliminated.
For example, variables 14, 50, 70, 85, and 87 in the puzzle of exercise 421 are forced
to be true; variables 61 and 76 are forced to be false. We can eliminate variables 05,
16, 27, 36, 54, 65, and 74 because 05 = -03, 16 = 36 = -25, 27 = 25, 54 = 74 = -63,
65 = 63. The options for the black clue become ‘15 01:1 03:1 34:1’, ‘15 03:0 07:1 34:1’.
The options for the white clue in the bottom row become ‘97 83:0’, ‘97 83:1’.
Caveat: These simplification are very nice, but they mess up the single-loop
detection mechanism of answer 413 — because that answer uses several fields of item
nodes as key elements of its data structure! To keep that algorithm happy, we must
append a special option that covers all of the supposedly eliminated vertex items and
constant-edge items; this option is ‘04 26 60 64 86 87:1 85:1 76:0 50:1 70:1 61:0 14:1’ in
the example. We also need pairs of options such as ‘#25 16:1 36:1 27:0 25:0’ and ‘#25
16:0 36:0 27:1 25:1’, to keep all variables of an equivalence class in sync.
A tenfold speedup is achieved even on small puzzles like the 8 x 10 in exercise 426.
424. As in answer 415, we can begin with the 1222363 loops that are potential so
lutions. But this time the “signature” of a loop is the maximum set of clues that it
supports. Such a signature turns out to have at most 24 clues; indeed, only puzzle (i) in
Fig. A-4, along with its rotations or reflections, attains this maximum. (At the other
extreme, 64 loops have an entirely empty signature, despite having lengths up to 28.)
July 26, 2019
244 ANSWERS TO EXERCISES 7.2.2.1
Let S be the set of 905472 distinct signatures; and let S' be the subset of 93659 projection vector
signatures that aren’t contained in any other. These are the signatures of loops that minimal elements of a family of sets
reachability
can solve a valid 6 x 6 puzzle. If s' G S' has t clues, we define the projection vector Hamiltonian cycle
p(s, s') = x1... xt for s G S by setting xj = 1 when s agrees with s' in the jth cell inverted
anonymous
where s' has a clue. For example, when s' is puzzle (i) and s is its transpose, the author
projection p(s,s') is 111010111101011110111011. balanced masyu solutions
Form the set P(s') = {p(s, s') | s = s'}. We know that 11... 1 / P(s'), because
s' isn’t dominated by any other signature. Moreover, the valid puzzles having the loop
of s' as their solution are precisely those whose clues are not contained in any element
of P(s'). We can find such puzzles, and the minimal ones, with a reachability compu
tation like Algorithm 7.1.3R, whose running time is O(2t). For example, the loop of (i)
turns out to be the solution to 8924555 puzzles(!). Four of them, such as (ii) and (iii),
are minimal with only four clues; three of them, such as (iv), are minimal with eleven.
Most elements of S' have far fewer than 24 clues. Hence it isn’t difficult to
determine that there are exactly 1,166,086,477 valid 6 x 6 masyu puzzles altogether, of
which 4,366,185 are minimal. (There are (80, 1212, 26188, 207570, . . . , 106) minimal
puzzles with (3, 4, 5, 6, . . . , 12) clues. One of the 3s is puzzle (v); it also has the shortest
loop. One of the 12s is puzzle (vi); it also has the longest loop—a Hamiltonian cycle.
(A Hamiltonian cycle can actually be forced by only four clues; see puzzle (xvii).)
The valid puzzles include 5571407 that are pure white, 4820 that are pure black.
The white clues can take on 22,032,015 different patterns; the black clues can assume
only 39140. A surprisingly large number of 6 x 6 puzzles, 37472, can be “inverted,”
remaining valid when white and black are swapped. If we restrict consideration to
minimal puzzles, these figures become: 574815 pure white, 1914 pure black, 2522171
white patterns, 22494 black patterns, 712 invertible. The latter include many amusing
and amazing pairs, such as (vii)-(viii), (ix)-(x), (xi)-(xii), as well as self-dual examples
such as (xiii), (xiv), (xv), (xvi); there are 49 essentially distinct invertible puzzles of size
6 x 6. [Considerably larger invertible puzzles have been published in the anonymous
blog uramasyu.blog80.fc2.com/, every few days since 2006.]
The author thinks puzzle (vi) may well be the hardest 6 x 6, although its search
tree via exercise 423 has only 212 nodes. (That tree has 1001 nodes with exercise 422.)
425. A “balanced” n x n masyu solution of order k clearly requires 2 < k < (n2/4j.
All such k turn out to be achievable, for n < 6, except that the upper limit |_n2/4_| is
not; see (xviii)-(xxiv) in Fig. A-4. (Solutions for k = 2 exist for all n > 3; solutions for
k = 3 exist for all n > 4. The situation for larger k and n has yet to be investigated;
for example, perhaps k = 4 is impossible for all large n.)
426. The clue in the corner must obviously be ‘®’. That leaves
us with 228 other possibilities to consider, many of which can be
rejected immediately because certain local patterns are impossible.
(For example, there cannot be three consecutive “•’, nor five 43’s
that form an X or T.) Consider the Boolean function of x0x1 . . . x27
that’s true if and only if the diagram has at least one solution, with
' • ’ when Xj = 1 and 43 ’ when xj = 0. One can easily verify that there’s no solution
when x0x1 or x1x3 or x0X1x4 or ... or X3X4X5 or x6x7 or X7X8X10Xn, etc.; also when
we replace xj by Xj+12. We can also rule out extreme cases such as X1x26.
After compiling several dozen such “bad” configurations, the author applied BDD
technology: Less than a megamem sufficed to generate a BDD of size
715, which showed that exactly 10239 vectors x0x1 . . . x27 were not
yet ruled out. The masyu solver of exercise 423 tossed off those
cases with search trees of 3 nodes per problem, on average; and it
turned out that exactly (10232, 1, 1, 1, 4) vectors had (0, 1, 2, 3, 4)
solutions. The unique winning puzzle is shown here (and solved in
Appendix E).
It turns out to be problematic for the method of exercise 423, which severely loses focus
focus and takes forever to prove that there’s only one solution. One can, however, symmetry
modifying Algorithm C
exploit symmetry by modifying Algorithm C as follows: Whenever a color setting is Nikoli
made on the rightmost branch of the search tree, all settings that are equivalent to it Beluhov
minimal
by symmetry can be forced. Then uniqueness is proved in about 36 M^, provided that invertible masyu
the primary items are suitably ordered. [This exercise was inspired by Nikoli’s Giant bitwise tricks
Logic Puzzles for Geniuses (Puzzlewright Press, 2016), #53.] magic blocks
429. (a) Incidentally, each of these puzzles is minimal (all clues important):
(b) In fact, two permutations of the colors are possible in each case:
430. (a) The lower right corner must contain 5. See Appendix E for the other cells.
(b) Set cnk ^ 0 for all n and k. Now do this for 3 < x < 512: Set k ^ n ^ 0; for
0 < t < 9 set k ^ k + 1, n ^ n +1 + 1 if x &(1 •< t) = 0; finally if k > 1, set Cnkcnk ^ x
and cnk ^ cnk + 1. The n-in-k combinations are now Cnkj for 0 < j < cnk.
The maximum cnk , 12, is obtained for (n, k) = (20, 4) or (25, 5). Notice that cnk =
c(45-n)(9-k) when 1 < k < 8. Cases with cnk = 1 are called “restricted” or “magic
blocks”; they’re extremely helpful when present (but our example doesn’t have any).
(c) The middle must be 7 9 8 (an odd digit < 9, 9, then an even digit).
(d) The tables from (b) convert kakuro to generalized kakuro. Introduce a primary
item ij for each cell to be filled. Let there be H horizontal blocks, and assume that
horizontal block h has ch combinations Xhp of length kh , for 1 < h < H and 1 < p < ch .
Introduce chkh primary items Hhpx, for x G Xhp, to represent the elements of block
h’s pth combination. (For example, the primary items for the first horizontal block of
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 247
our example are H111 , H114, H122 , H123 because the two combinations are {1, 4} and color
{2, 3}.) Similarly, introduce primary items Vvqy for the elements of the qth combination preprocessing
focus
Yvq of vertical block v, for 1 < v < V and 1 < q < dv. copyright
Also introduce secondary items Hh and Vv for 1 < h < H and 1 < v < V, one for restricted growth strings
permutations
each block. The “color” of such an item represents the choice of combination to be used. dual
The options for cell ij are ‘ij Hhpx Hh:p Vvqx Vv :q’, where h and v indicate
the horizontal and vertical blocks through ij , for 1 < p < ch and 1 < q < dv and
x 6 Xhp П Yvq. (Thus, the options for the upper left blank cell in our example are
‘11 H111 H1:1 V111 V1:1’, ‘11 H114 H1:1 V124 V1:2’, ‘11 H122 H1:2 V122 V1:2’. Set
intersections are easily computed from the bitmaps Xhp and Vvq.)
Additional options are also necessary to “absorb” the combinations not used.
These are ‘U{Hhpx | x 6 Xhp} Hh:p'’ for 1 < p,p' < ch and p = p; ‘U{Vvqy | У 6 Yvq}
Vv :q'’ for 1 < q, q' < dv and q = q'. (Thus the options for h = 1 in our example are ‘H111
H114 H1:2’, ‘H122 H123 H1 :1’.) This instructive construction deserves careful study.
431. There are 18 solutions, because of two ways to complete the middle left portion
and (independently) nine ways to complete the lower left corner. (The digits that
are uniquely determined by his conditions are shown below.) We can freeze most of
those digits, and extract two much smaller problems, then insert a few wildcards as
in exercise 433 until obtaining uniqueness. One suitable patch, shown below, changes
seven clues and has the solution found in Appendix E. (In this problem, preprocessing
greatly improves the focus, reducing the search tree size from 115 million to just 343!)
3 7 8 9 5 1 2 5 7 9 8
1 2 3 5 6 2 5 4 2 1 9
2 4 5 6 7 8 9 8 2 1 3 4
2 3 4 9 6 8 5 1 1^
2 1 4 5 7 7 4 3 1 2 6
1 4 2 9 8 2 3 7
4 5 2 1 4 9 7 4 8
5 6 7 3 4 7 9
4 8 5 7 3 4 1 2
2 1 3 6 7 9 4 5
J6j41 7 9 2 6 4 5
22 I 2
” 5 9 8 1 8 3
1 2 6 5 9 7 8
[Funk had copyrighted a Cross Sums Puzzle already in September 1935; see Canadian
Patent Office Record and Register of Copyrights and Trade Marks 63 (1935), 2253.]
432. (a) We save a lot of time by considering only “restricted growth strings” as
solutions (see Section 7.2.1.5). That is, we can assume that the top row is ‘12’; then the
second row is either ‘213’ or ‘234’ or ‘312’ or ‘314’ or ‘34x’ for 1 < x < 5; etc. Altogether
there are (5, 28, 33, 11, 1) such strings with maximum element (3, 4, 5, 6, 7). Thus we
know that the blanks can be filled in 5 • 93 + 28 • 94 + 33 • 95 + 11 • 96 +97 = 1432872 ways.
And we can quickly compute the 1432872 sequences of block sums from those restricted
growth strings, using a table of 9! permutations built by Algorithm 7.2.1.2L. Exactly
78690 of those sequences, about 5.5%, occur uniquely and define a kakuro puzzle.
Every kakuro puzzle has a dual, obtained by replacing all clue-sums s for blocks
of length k by 10k - s; the dual is solved by changing each digit d to 10 - d. Thus, if
a puzzle of type (a) is defined by horizontal and vertical sums s1s2s3/t1t2t3, its dual is
July 26, 2019
248 ANSWERS TO EXERCISES 7.2.2.1
436. (a) Any solution with a black seed works also with that cell white. 2SAT
median
(b) A solution with a non-articulation point would work also with that cell black.
triply linked
437. Introduce a primary item * to make the seeds white; also primary items Ric and spanning tree
articulation points
Cjc for each character c that occurs more than once in row i or column j. Introduce Hopcroft
secondary items ij for 0 < i < m and 0 < j < n, representing cell (i, j). For example, Tarjan
bicomponents
the first option for puzzle 436(a) is ‘* 01:0 02:0 10:0 13:0 14:0 21:0 31:0 32:0’. vertex cover
Suppose row i contains character c in columns j1 , . . . , jt, where t > 1. Then Ric Garey
normally has t + 1 options ‘Ric ij1:e1 ... ijt:et u1:0 ... us:0’ for e1 + • • • + et > t — 1, Johnson
NP-complete
where {u1 , . . . , us} are the non-seed neighbors of the cells being colored 1. However, Beluhov
this option is suppressed if it would assign two colors to the same item. For example, frontier
if i = 1, t = 3, and j1j2j3 = 123, there is only one option ‘R1c 11:1 12:0 13:1 01:0 03:0 ZDD
NONSUB subroutine
10:0 14:0 21:0 23:0’ (but with entries deleted that color a seed with 0), because the f*
other three options are contradictory.
Of course the options for Cjc are similar. For example, the options for c3l in
puzzle 436(a) are ‘c3l 23:0 33:1 34:0’ and ‘c3l 33:0 23:1 22:0 24:0’.
[Notice, incidentally, that this XCC problem is a special case of 2SAT. Therefore
it can be solved in linear time. Furthermore, by Theorem 7.1.1S, the median of any
three solutions is also a solution — a curious fact!]
438. The basic idea is to abandon partial solutions that cut off any white cells from
the first seed. Connectedness can be assured by maintaining a triply linked spanning
tree, rooted at that seed, with the help of new fields in each item record. Changes to
the spanning tree need not be undone when unblackening a cell while backtracking;
any spanning tree on the currently nonblack cells is satisfactory.
[This method can be patched to handle the rare instances that have no seeds.
To ensure uniqueness, as in exercise 436(b), each solution should also be tested for
articulation points. Hopcroft and Tarjan’s algorithm for bicomponents does that
efficiently. See Section 7.4.1; also The Stanford GraphBase, pages 90-99.]
439. (a) Property (ii) states that U is a vertex cover (or equivalently that V \ U is
independent). Thus (i) and (ii) together state that U is a connected vertex cover.
Adding property (iii) gives us a minimal connected vertex cover. [Minimal connected
vertex covers were introduced by M. R. Garey and D. S. Johnson in SIAM J. Applied
Math. 32 (1977), 826-834, who proved that it is NP-complete to decide if a planar
graph with maximum degree 4 has a connected vertex cover of a given size.]
(b) This is the thrust of exercise 436(b). [N. Beluhov has proved constructively
that every m x n hitori cover for m,n > 1 solves at least one valid puzzle, using an
alphabet of at most max(m, n) letters.]
A B A 0 A B C D A 1
440. False (if neither A is alone in its column). Consider B C A B 2 3 4 5 6 D
A C C B A B C D A D
441. When n = 1 any single letter a is trivially a valid puzzle. When n > 1 the pos
sibilities are (i) aaa for every string a of n — 2 distinct letters containing an a (thus
(n — 2)dn-2 puzzles); (ii) aab for a = b and every string a of n — 2 distinct letters
containing a and b (thus (n — 2)2 dn-2 puzzles); altogether (n — 2)2 dn-2 valid puzzles.
442. A “frontier-based” algorithm analogous to those of answers 7.1.4-55 and 7.1.4-225
will produce an unreduced ZDD for the family f of all complements V \ U of connected
vertex covers, from which a variant of Algorithm 7.1.4R will give a ZDD. Then the
NONSUB subroutine of answer 7.1.4-237 will produce a ZDD for f *, the complements of
hitori covers (the black cells of potential solutions). In the most complicated case, m =
July 26, 2019
250 ANSWERS TO EXERCISES 7.2.2.1
n = 9, an unreduced ZDD of size 203402 is reduced quickly to 55038 nodes; then 550 G// horizontal and vertical symmetry
of computation produces a ZDD of size 1145647 for the family of maximal black cells. 8-fold symmetry
4-fold symmetry
Those ZDDs make it easy to count and generate hitori covers; we obtain the totals 90° rotational symmetry
symmetry about both diagonals
12 1 1 1 1 1 1 1 A
24 6 12 20 36 64 112 200
16 11 30 75 173 434 1054 2558
1 12 30 110 382 1270 4298 14560 49204
1 20 75 382 1804 7888 36627 166217 755680 .
1 36 173 1270 7888 46416 287685 1751154 10656814
1 64 434 4298 36627 287685 2393422 19366411 157557218
1 112 1054 14560 166217 1751154 19366411 208975042 2255742067
1 200 2558 49204 755680 10656814 157557218 2255742067 32411910059
Further statistics about these fascinating patterns are also of interest:
([1..1] [1..1] [2 ..2] [2..2] [2..2] [2..2] [2..2] [2..2] [2..2] \ /10 1111 1 11\
[1..1] [1..1] [1 ..2] [2..2] [2..3] [2..3] [3..4] [3..4] [3..5] 00 0 0 0 0 0 0 0
[2..2] [1..2] [2 ..4] [2..4] [3..6] [4..6] [4..8] [5..8] [5..10] 103251 6 2 10
[2..2] [2..2] [2 ..4] [4..5] [4..7] [5..8] [6..9] [7..10] [8..12] 102020 2 0 2
[2..2] [2..3] [3 .. 6] [4..7] [5..9] [6..10] [8..12] [9..14] [10..15] 10 5 2102 21 1 46
[2..2] [2..3] [4 .. 6] [5..8] [6..10] [8..12] [9..14] [11..16] [12..18] 101020 1 0 2
[2..2] [3..4] [4 ..8] [6..9] [8..12] [9..14] [11..17] [12..19] [14..21] 1 0 6 2 21 1 48 1150
[2..2] [3..4] [5 ..8] [7..10] [9..14] [11..16] [12..19] [14..21] [16..24] 102010 1 03
[2..2] [3..5] [5..10] [8..12] [10..15] [12..18] [14..21] [16..24] [18..27] 101024621503649
The left-hand matrix shows how many black cells can occur in hitori covers. The
right-hand matrix shows how many hitori covers have both horizontal and vertical
symmetry; when m = n, such covers are counted just once in the previous totals, while
the unsymmetrical covers are counted twice or four times. When m = n, such covers
are counted either once (if there’s 8-fold symmetry) or twice (otherwise); there are
respectively (1, 0, 1, 0, 2, 0, 2, 0, 11) n x n hitori covers with 8-fold symmetry. Further
types of 4-fold symmetry are possible when m = n: There’s 90° rotational symmetry
(but not 8-fold) in (0, 0, 0, 1, 1, 3, 11, 30, 106) pairs of cases; there’s symmetry about
both diagonals (but not 8-fold) in (0, 0, 0, 0, 0, 1, 4, 9, 49) pairs of cases. Figure A-5
shows some of the winners in this beauty contest for symmetrical hitori covers.
Fourfold horizontal and vertical symmetry is impossible when m and n are both
even, because it forces at least 12 white cells near the center. The number of 2 x n
July 26, 2019
7.2.2.1 ANSWERS TO EXERCISES 251
hitori covers can readily be shown to satisfy the recurrence Xn = 2Xn-2 + 2Xn-3, recurrence
growing as 0(rn) where r ~ 1.76929. Beluhov
Beluhov
443. (Solution by N. Beluhov.) Let there be s black cells, of which a lie in the interior, seed
RC problem
b on the boundary but not in a corner, and c in a corner. One can show that b + 2c < bipartite matching problem
m+n+2 - [m even] - [n even] - [mn odd]. Therefore the number of edges in Pm Pn | U
is m(n - 1) + (m - 1)n - 4a - 3b - 2c = 2mn - m - n - 4s + b + 2c < 2mn - 4s + 1.
But Pm Pn | U is connected, so it has at least mn - s - 1 edges.
[Beluhov has also proved that the number of black cells is always at least mn/5 -
O(m + n). One can obtain a small hitori cover by blackening (i, j) when i + 2j is a
multiple of 5, and possibly a few more cells; this cover has at most mn/5+2 black cells.]
0 0 1 0 2 3 0 4 5
444. No. By exercise 443, the solution has at most |_(n2/3 +2)/n_| black 0 1 0 2 3 0 4 5 0
cells in some row. This is at most n/3, when n > 5; hence 2n/3 elements 1 6 2 3 0 4 5 0 0
0 2 3 6 4 5 0 0 1
of that row are white. Conversely, the puzzle illustrated here for n = 9 2 3 0 4 5 0 0 1 0
3 0 4 5 6 0 1 0 2
can be generalized to 3k x 3k for all k > 1. (It’s a simplification of a con 0 4 5 0 0 1 6 2 3
4 5 0 0 1 0 2 3 0
struction by N. Beluhov. Notice that every nonzero element is a seed!) 5 0 0 1 0 2 3 6 4
445. Array (a) below is a seedless puzzle that corresponds to (ii), if you change its
lowercase letters to uppercase. (The lowercase letters are convenient for our purposes in
understanding seedlessness, because they indicate the cells that we’ll want to darken.)
When every black cell has a different letter to be hidden, a seedless puzzle must fill
each white cell (i, j) with a hidden letter from either row i or column j.
Given a hitori cover, its “RC problem” is to put either R or C into each white
cell so that the number of Rs in each row is at most the number of black cells in that
row, and the number of Cs is similar but for columns. Array (в) shows the RC solution
that corresponds to (a); this is one of four ways to solve the RC problem for (ii).
Suppose a hitori cover has s black cells. Every solution to its RC problem has at
most s white cells marked R and at most s marked C; so we must have s > n 2/3 in an
n x n cover. Consequently s must be 12 when n = 6, by exercise 443. In particular, pat
tern (i) can’t lead to a seedless puzzle. Also, equality must hold when we said “at most.”
It’s easy to formulate the RC problem as an MCC problem, by introducing a
primary item ij for each white cell (i, j), also primary items Ri and Cj for each nonwhite
row i and column j. In the problem for pattern (ii) we have, for example, two options
‘23 R2 ’ and ‘23 C3’ for item 23. The multiplicity of C3 is 2. (This is actually a bipartite
matching problem; we use Algorithm M only because of the multiplicities.)
Array (y) shows a seedless puzzle different from (a) that comes from the same
RC solution (в). Indeed, (в) yields 3!1!2!2!1!3! • 3!1!2!2!1!3! = 20736 different seedless
puzzles, because the letters chosen in each row and column can be permuted arbitrarily.
All such permutations yield valid puzzles. Proof: Each of the 12 letters occurs
thrice. To solve the puzzle we must blacken each letter at least once, preserving white
connectedness. One successful solution is to kill two birds with each stone; any other
way would blacken 13 or more. But no 6 x 6 hitori cover has more than 12 black cells.
Pattern (iii) has eight RC solutions, and 20736 seedless puzzles for each of them.
Pattern (iv) has no RC solutions. But pattern (v) has the unique solution (5),
and one of its 3!0!3!2!1!3! • 2!2!1!3!1!3! = 62208 seedless puzzles is (e).
a A p P B b R a P p A B b R R R A A B B C C
A W Y w X B CRC S W P w X Q C C C G A I B H C
S z Q R Z q (в) RCR A z Z R Q q (5) R R R
(0
D D E E F F
s X P S x Q RCR s X Y S x B G G H E H F
D Z y W Y C CRC D Z y W Y C J D I K I L
d D R r C c R d C D r R c R J J K K L L
[N. Beluhov has proved that valid n x n seedless puzzles exist ^^ n mod 6 = 0.] Beluhov
Bible
446. There are only 1804 hitori covers, according to answer 442; but the exact proba Sicherman
bility appears to be difficult to compute. Experiments with millions of random numbers Falstaff
author
show convincingly, however, that the probability is ~ .0133. It drops to ~ .0105 with graffiti
radix 8, and even further to ~ .0060 with radix 16; the “sweet spot” appears to be Sullivan
radix 10(!). [Also, the probability for decimal 4 x 4 is « .0344; for 6 x 6 only « .0020.] Rogers
poem
447. Yes, when 2 < m < 4 and n = 6! (Johan discovered the 4 x 6, and the 5 x 5
for e, in 2017. The cases 2 x 6, 3 x 2, and 4 x 5 also work for e. By exercise 443, we
can assume that m,n < 15.)
448. There are just two answers. (Also a nice 6x6 with only one not-so-common word.)
S C H E M A
T A S T E I D L E D
H A U L E D
U P P E R S W E A R
I S S U E D
F R I A R L E A S E
R E T A K E
T O R S O E L V E S
T I L T E R
S N E E R S L E D S
S N E E R S
449. A few more nuggets: Johan noticed (i) in the (appropriately named) 1990 movie
Home Alone; and he found (ii) in the King James Bible, Luke 9 : 56. George Sicherman
hit on Falstaff’s famous repartee (iii) in 1 Henry IV, Act V, Scene 4, Line 119. The
author found (iv) within the graffiti on page 278 of CMath; also (v), an inspiring
remark by Francis Sullivan, on page 2 of Computing in Science and Engineering 2, 1
(January/February 2000). Example (vi) appears in the front matter to Volume 1. And
example (vii), also 11 x 3, shows that a nice hitori can involve lowercase letters, spaces,
and punctuation; it’s a quote from Samuel Rogers’s poem Human Life (1819).
D O Z N e v
G R E A
F O R T H E E N S e r
T H E B W E L L T A L G
S O N O F M O F N l e s
M E R R E T T E T H E Y O R I T
A N I S N O E W E s a
Y C H R R P A R C A N T H M S A
T C O M E T X E R l o n
I S T M T O F V R E A L R E T H
(i) A S S W
(ii) O D E S T R (iii) A L O R
(iv) L Y G O
(v) E P O E
(vi) C I S (vii) e t
O Y M E N S E S H h a n
E E T H I S D I A T I T T R Y O
L I V E S B A V E w h
E A R T S C R E T H I S F C O M
U T T O S A B E E e n
T I O N L O N G P U T A
V E T H E M N A D a l o
T I O N
D E D n e .
1 2 8 Э 7 9 4 6 5 8 1 2 Э 4 5 6 9 7
4 6 7 1 5 2 9 8 Э Э 9 6 1 7 2 4 5 8
9 Э 5 8 6 4 7 2 1 5 4 7 6 Э 2 1
Э 9 4 6 2 8 5 1 7 7 2 4 5 1 6 Э
8 7 6 5 9 1 2 Э 4 (see answer 52) 6 Э 2 1 7 4 5 (see answer 58)
2 5 1 7 4 Э 6 9 8 4 5 1 6 Э 7 2
5 4 Э 2 1 6 8 7 9 1 7 4 5 2 Э 6
6 1 9 4 8 7 Э 5 2 9 6 Э 7 2 1 5 8 4
7 8 2 9 Э 5 1 4 6 2 8 5 6 Э 4 7 1 9
fl
fl4fl fl
fl
4 fl
fl
fl *
fl *
* 4ъ4 * fl
fl
fl
fl
fl * fl
(see
answer
173)
fl fl
fl
44 fl
fl fl
fl fl fl
fl fl (see answer 174)
fl4 fl fl fl fl
fl
4 fl
fl fl fl
3T 4|2|6|9|7|^8
7694 15 9 2 6 82
82 278124.5
5227461
(see answer 282) 58
46 6124272 (see answer 302(c))
15. 7812222
2642827
2[7 2478216
92 8з|5|б| 1|^4
red bot = 1st
335
,, mid = 278
435
,, top = 266
446
; green
866,
bot = 868 , mid 81
, top =
443
112
433
(see answer 337)
0 [4]<[S]<[T]<[S] [1 И<И [2
8 Ш [2] [5]<[6]<И и [3 [4
3 [3 [4 [2] [5
9 И Ш [6]<[7]<М [1]<[2]<[3
1] И [2]<[4] [3
S]<[7]<[S] Ш И [2] [3]<[4]<[6
5 И [1]<[3] [4
(see answer 395) 1]<[2]<[3]<[4] [5 [6] [7]<[3] [9 (see answer 396)
2]<[3]<[6]<[3] И И [4]<[5]<[7
2 [4 > 3 [5 [1
6]<[8]<[9] [3]<[4]<[S] [2 И [1
4 [6]<[7]<М [2]<[3] И И 0
3^ 14 X 15X 9+ 2^ 6^
9 7 2 3 5 8 4 6 1
5+ 35+ 8 9^
3 2 6 5 4 7 8 1 9
2 1 5 4 7 6 3
7+ 9
9
32X
8
23 24 31 32 6 5 14 13
3 84X 62+ 64X
5 6 7 2 3 9 1 8
3
4 22 30 25 17 7 15 4 12
8 5 9 7 6 1 2 4 3 (see answer 403) (see answer 407)
6 9
3
3
8+ 32X 79+ 50X
1 8 4 7 2 5 21 29 18 26 16 8 3 11
7 8 4 6 1 3 9 5 2
1 4 8 9 2 5 6 3 7
20 19 28 27 1 2 9 10
2 8 378 X
4 3 1 8 9 2 5 7 6
1 2 3 4 5 6 3 2 7 6 11 10
28 29 16 17 7 19 1 4 5 8 9 12
27 15 30 8 18 20 22 23 18 19 13 15
(see answer 408)
14 26 9 31 21 36 24 21 20 17 16 14
13 10 25 22 32 35 27 25 31 30 33 36
11 12 23 24 34 33 26 28 29 32 35 34
60 30 31 32 33 34 35 41 40 39
59 61 29 26 27 54 53 36 42 38
62 58 25 28 55 97 52 93 37 43
63 24 57 56 98 96 94 51 92 44 |3222 22
2222 3|2
23 64 84 85 86 99 95 91 50 45 2 2 2 2 2 2
(see answer 409) 2|2 2 222
(see answer 411)
22 21 65 83 100 87 88 90 49 46
2|3|2 2 2 2|
19 20 66 67 82 81 80 89 48 47 2 2 2рТ23|
18 69 68 74 75 1 79 3 5 6
70 17 73 76 14 78 2 4 7 9
71 72 16 15 77 13 12 11 10 8
■Л3333333333333
о^ГЗо' '0 '0 '0 '° ' 4444444'114' 3 ___________________________]
ГоЗ ' 'о' ' ' 'о' ’ ' '1[ 1 1 1.1.1 111 11 2 2 2 2 2 2 2 2 212 3 ] '
оЗ О' ' ' ’о' ' ' ’о' '11 '1'1'1'1'14'1 11 2 2 2 2 2 2 2 2 212 2 3 1333333333333
СО о о 1 1 1 144.1.144' 2 2 2 212 2 2 212 2 2 3 I
оЗ По' ' ' 'о' ' ' 'о' '1 1'1 44444'14' 2 2 2 2121 22 2 2 2 3 1333333333333 О1
ГоЗ ■ v ' ' 'о' ■ ■ '11 4 1 1.1.1 1 1 11 2 2 2 2 З2З2 2 2 3 1
О Со' ' ' ’о'
СО ' 'о' ’ '
' ' ’о'
'о' ■'
'11 44444'11 ]1 2 2 2 212 32|2 2 2
2 2 2 232 2|2|2 2 2
3 1333333333333 1'1'1 11 (see answer 416)
4 14[ '1111111 3 I 1.1.1.1.
О Со' ' ' 'о' ' ' 'о' 4 1'1 4444'114' 2 2 232 2 2 2 2 2 2 3 1333333333333
ПО ' 'о' ' ' 'о' ■ ' 4 1 4 1 1.1.1 1 1 11 2 2 212 2 2 2 2 2 2 2 3 1
О Со' ' ' ’о' ' ' ’о' '1 444444'11 |1 232 2 2 2 2 2 2 2 2 3 1333333333333
СО ' 'о' ’ ' 'о' ■ ■ ' 1111111111
32 2 2 2 2 2 2 2 2 2 3 I
оООо' ' ' 'о' ' ' 'о' 33333333333333
1'
(see answer 418)
SHAKESPEARE
BEI G N A M I
3 415 9
И_ R I I T <V E N
2 653 8
(see answer 447) A M N O R I yIo (see answer 449)
79 3
fJoIn epFi D N O
8 4
MAK YO U M A D
When an index entry refers to a page containing a relevant exercise, see also the answer to
that exercise for further information. An answer page is not indexed here unless it refers to a
topic not included in the statement of the exercise.
Baillie, Andrew Welcome Spencer, 215. Bipartite graphs, 43, 64, 120, 174.
Balanced coloring, 62. Bipartite matching problems, 39, 40, 64,
Balanced masyu solutions, 244. 70, 85, 90, 91, 177, 251.
Ball-piling, 104—105. Biquadruples, 176.
Barlow, David Stewart (= Abaroth), 210. Birthday greeting, 36.
Barnes, Frank William, 218. Bishop moves, 81-82.
Barris, Harry, 1. Bit vectors, 236.
Barwell, Brian Robert, 209. Bitland, 67.
Barycentric coordinates, 104—105,
Bitmaps, 117.
150-151, 162.
Bitner, James Richard, 230.
Base placements, 97-98, 100, 105, 188-189,
201, 222, 232. Bitriples, 86, 176.
Basis theorem for packing, 109, 230. Bittencourt Vidigal Leitao, Ricardo,
Baxter, Nicholas Edward, 106. 142, 143, 147.
BDD: A reduced, ordered binary decision Bitwise operations, 8, 12, 63, 80.
diagram, 232, 245, 248. AND (&), 64, 123, 246.
Bean, Richard, 235. median ((xyz)), 249.
Beauty contest, 74, 88, 92, 94, 98, 250. OR (|), 64.
Becker, Joseph D., 221. Bjorklund, John Nils Andreas, 85, 175.
Beeler, Michael David, 204. Black and white cells, 21-22, see
Behrens, Walter Ulrich, 14, 15, 65. Parity of cells.
Bell, Eric Temple, numbers, 37-38, 234. Blair, Eric Arthur [= Orwell, George], 119.
Bell, George Irving, III, 220-222. Blecher, Aubrey, 173.
Beluhov, Nikolai Ivanov ( Bloch, Cecil Joseph, 223.
), iv, 82, 113, 114, 169, 170, 186, Blocked items, 45.
239, 241, 242, 246, 248, 249, 251, 252. Blocks in kakuro, 116-118.
Benchmarks, 17, 194. Boddington, Paul Stephen, 159.
Bender, Edward Anton, 201. Body-centered cubic lattice, 222.
Benedek, Gyorgy Mihaly Pal (= George Boolean functions, 232.
Mihaly Pal = ГЛП hXD ХПР5), 238.
Boothroyd, Michael Roger, 155.
Benjamin, Herbert Daniel, 93, 95, 198, 209.
Borel, Eamile Faelix Eadouard Justin, 23-24.
Bennett, Frank Ernest, 136.
Bent tricubes, 102, 232. Bottleneck optima, see Minimax solutions.
Bent trominoes, 15, 18, 213. BOUND, 33-34, 81.
Berg, Alban Maria Johannes, 71. Bounded permutation problem, 39,
Berlekamp, Elwyn Ralph, 22, 210. 84, 85, 90.
Berthier, Denis, 129. Bounding box, 66.
Bertrand, Joseph Louis Francois, 23-24. Bounds in futoshiki, 110.
Besley Tollefson, Serena Sutton, 214. Bousquet-Melou, Mireille Francoise, 134.
Bessel, Friedrich Wilhelm, functions, Boutillier, Caedric Graegory Marc, 187.
generalized, 200. Bouwkamp, Christoffel Jacob, 189, 215, 217.
BEST, 53. Bower, Richard John, 218.
Biaxial symmetry, 110, 169, 232, 250. Boxes in sudoku, 10, 14, 65.
Bible, 252. Boyer, Christian, 128.
Bicomponents, 100, 249. Bradley, Milton, 156.
Bidiagonal symmetry, 107, 110, 250. Branch, choice of, see MRV heuristic,
Biggs, Norman Linstead, 227. Nonsharp preference heuristic, Sharp
Bilateral symmetry, 110, see Biaxial preference heuristic.
symmetry.
Breadth-first search, 63-64.
Binary Arts, 164.
Breaking symmetry, see Symmetry breaking.
Binary constraints, 70.
Binary notation, 62. Brennan, Charlotte Alix, 173.
Binary operators, 41, 68, 85-86, 128, 232. Bricks, 18, 79, 104.
Binary search, 139. Brotchie, Alaistair, 141.
Binary search trees, 60, 128. Brouwer, Andries Evert, 134.
Binary vectors, 44. Bruijn, Nicolaas Govert de, 18, 59, 104, 230.
Bipair: Two pairs of options that cover cycles, 27, 70, 91.
the same items, 43-44, 55, 86-87, Bundgard, Thorleif, 211.
93, 177, 189, 196, 203. Burnside, William Snow, lemma, 154, 169.
Geek art, 201, 215. Guy, Richard Kenneth, 22, 172, 195,
Geerinck, Theodorus, 217. 204, 210, 215.
Generalized kakuro, 117.
Generalized toruses, 205. H-grid, 207.
Generating functions, 84, 85, 96, 122,
Hadamard, Jacques Salomon, 23-24.
134, 185.
transform, 219.
exponential, 83-84, 122.
HAKMEM, 204.
Generic option, 45.
Hall Emlong, Ruby Charlene Little, 211.
Geometric sudoku, 14.
Hamaker, William, 218.
Gerechte designs, 15, 65.
Hamilton, William Rowan, cycles,
Gerry, Elbridge, 67.
79, 238, 244.
Gerrymandering, 67.
king paths, 239.
Gessel, Ira Martin, iv. paths, 112.
Giant component, 80, 140. Hamming, Richard Wesley, distance, 62-63.
Gibat, Norman Edlo, 144. Hansson, Frans, 16, 17, 95, 192, 197, 215.
Gilbert, Edgar Nelson, 143-144.
Hardest sudoku puzzle, 65.
Gillen, Marcel Robert, 195.
Harris, Robert Scott, 14, 133.
Glaisher, James Whitbread Lee, 23-24.
Haselgrove, Colin Brian, 190.
go to statements, 150.
Haselgrove, Jenifer Wheildon-Brown
Golden ratio (ф), 63, 155.
(= Leech, Jenifer), 42, 190, 194.
Goldenberg, Mark (= Meir) Alexandrovich
Hash function, 185.
( ),
Haswell, George Henry, 156.
230.
Haubrich, Jacob Godefridus Antonius
Golomb, Solomon Wolf, 15, 16, 20,
(= Jacques), 157.
93, 190, 206.
Hawkins, Harry, 193.
Gompertz, Benjamin, 38, 173.
Hayes, Brian Paul, 11.
Gondran, Michel, 182, 183.
Header nodes, 1-4, 25, 60, 120, 184.
Goodger, David John, 210.
Gordon, Leonard Joseph, 145, 146, 221, 222. Heads and tails puzzles, 76.
Gosper, Ralph William, Jr., 206. Heap ordered arrays, 53.
Gosset, John Herbert de Paz Thorold, 125. Heavy-tailed distribution, 135.
Gottfried, Alan Toby, 151, 158. Height of a binary tree, 120.
Gould, Henry Wadsworth, 38. Hein, Piet, 18, 19, 100, 211, 221.
numbers, 37-38, 83-84, 173. Henle, James Marston, 133, 236.
Gould, Wayne, 129. Hensel, Kurt Wilhelm Sebastian, 23-24.
Goulden, Ian Peter, 201. Heptacubes, 215.
Graatsma, William Petrus Albert Roger Heptiamonds, 204, 205.
Stephaan, 20. Hermite, Charles, 23-24.
Grabarchuk, Petro (= Peter) Serhiyovych Hertog, Martien Ilse van, 227.
( ), 132. Hexacubes, 215.
Grabarchuk, Serhiy Oleksiyovych Hexadecimal digits, 112.
( ), extended, 9, 16, 188.
97, 132. Hexagonal close packing, 106.
Graffiti, 252. Hexagons, 78, 98.
Graham, Ronald Lewis ( ), 224, 258. coordinates for, 98.
Gram, J0rgen Pedersen, 23-24. Hexiamonds, 77, 97, 207.
GRAND TIME puzzle, 14. Hexominoes, 15, 65, 95.
Graph coloring, 62, 73, 93, 199. Hexotinoes, 204.
Gravitationally stable structures, 100, Hidato®, 112-113.
102, 213. Hidden mathematicians, 23-24.
Greedy algorithm, 183. Hidden singles and pairs, 12-13, 64,
Greedy queens, 63. 129, 233.
Grensing, Dieter, 186. hide(p), 5.
Gropes, 68. hidez(p), 26, 56, 90.
Groupoids, see Binary operators. hidezz(p), 45, 185.
Groups, 136. Hiding an option, 5, 53.
Griinbaum, Branko, 189, 192. Hilbert, David, 23-24, 231.
Guy, Michael John Thirian, 22, 210. Hill, Gerald Allen, 211.