Artificial Intelligence Problems and Their Solutions
Artificial Intelligence Problems and Their Solutions
Problems
AND THEIR SOLUTIONS
License, Disclaimer Of Liability, And Limited Warranty
By purchasing or using this book and disc (the “Work”), you agree that
this license grants permission to use the contents contained herein,
including the disc, but does not give you the right of ownership to any
of the textual content in the book / disc or ownership to any of the
information or products contained in it. This license does not permit
uploading of the Work onto the Internet or on a network (of any kind)
without the written consent of the Publisher. Duplication or dissemi-
nation of any text, code, simulations, images, etc. contained herein is
limited to and subject to licensing terms for the respective products,
and permission must be obtained from the Publisher or the owner of
the content, etc., in order to reproduce or network any portion of the
textual material (in any media) that is contained in the Work.
The sole remedy in the event of a claim of any kind is expressly limited
to replacement of the book and/or disc, and only at the discretion of the
Publisher. The use of “implied warranty” and certain “exclusions” vary
from state to state, and might not apply to the purchaser of this product.
Artificial Intelligence
Problems
AND THEIR SOLUTIONS
This publication, portions of it, or any accompanying software may not be reproduced in any way,
stored in a retrieval system of any type, or transmitted by any means, media, electronic display or
mechanical display, including, but not limited to, photocopy, recording, Internet postings, or scanning,
without prior permission in writing from the publisher.
D. Kopec, S. Shetty, & C. Pileggi. Artificial Intelligence Problems and Their Solutions.
ISBN: 978-1-938549-83-0
The publisher recognizes and respects all marks used by companies, manufacturers, and developers
as a means to distinguish their products. All brand names and product names mentioned in this book
are trademarks or service marks of their respective companies. Any omission or misuse (of any kind) of
service marks or trademarks, etc. is not an attempt to infringe on the property of others.
141516321
Our titles are available for adoption, license, or bulk purchase by institutions, corporations, etc.
For additional information, please contact the Customer Service Dept. at 1-800-758-3756 (toll free).
Digital versions of our titles are available at: www.authorcloudware.com
The sole obligation of Mercury Learning and Information to the purchaser is to replace the
book and/or disc, based on defective materials or faulty workmanship, but not based on the operation
or functionality of the product.
CONTENTS
Preface ..............................................................................................................xi
List of Figures and Tables ...................................................................................xiii
Chapter 14: Conclusion: Toward a Theory for Problem Solving ... 233
14.1 Human Window Study ........................................................................233
14.2 Lessons Learned .................................................................................233
14.2.1 The Missionaries and Cannibals Problem.................................235
14.2.2 The 12 Coins Problem ...............................................................235
14.2.3 Cryptarithms ..............................................................................236
14.2.4 The Red Donkey Puzzle ............................................................237
14.2.5 The 15 Puzzle .............................................................................238
14.2.6 The Knight’s Tour Problem .......................................................238
14.2.7 Mastermind ................................................................................238
14.2.8 The Monty Hall Problem...........................................................239
14.2.9 Rubik’s Cube ..............................................................................239
14.2.10 The Prisoner’s Dilemma ..........................................................239
14.2.11 Miscellaneous Problems ..........................................................239
14.3 Retrospective, Conclusions, and Future Work ..................................240
14.4 Supplemental References ...................................................................241
14.5 Composite Problem Playability Sites..................................................243
Index .............................................................................................................247
PREFACE
We live in times that are transitional and fast-paced. Just about every-
one seems to own at least one electronic device, such as iPhones, smart
phones, notebooks, and so on, that they consider vital to their existence.
Patience is short, and everyone wants quick results (e.g., Google) without
having to do a lot of difficult research. Students come to classes unabash-
edly deploying these devices, and instructors don’t know if they’re text mes-
saging/social networking, or addressing the topic at hand. Attention spans
seem to be very short. We are consistently distracted by the small things that
need to, or can, be done. In the end, our lives seem to be made up of small,
choppy episodes as we go about conducting our daily tasks. The notion
that one sits still at a desk uninterrupted for many hours seems foreign to
our society today. Persistence, trial and error, search, inquisitiveness, and
simply “thinking” appear to be activities of the past. And it is clear that
there will be no turning back from this technological age and our depen-
dencies on technology. Yet, over and over again, we hear that our children’s
test scores are declining.
One perspective on intelligence measures the ability to solve problems.
Another considers how an individual or a society is able to survive under
adverse conditions. So the natural question is: what will happen to our
society and our children if someone “turns off the power”?
Therefore, a book about solving problems that uses nontrivial and some-
times difficult problems is especially timely, because it addresses the needs
of a number of possible constituent audiences. This book assembles in one
place a set of interesting and challenging artificial intelligence (AI)–type
problems that students regularly encounter in computer science, mathe-
matics, and AI courses. These problems are not new, and students from
xii • Artificial Intelligence Problems and Their Solutions
all backgrounds can benefit from the kind of deductive thinking that goes
into solving them. Another constituent audience is the computer science,
mathematics, or AI instructor who is looking for answers to these problems.
This book explores the kinds of thinking, methods, and applications used
in computer science and AI to solve these problems. Furthermore, a solid
understanding of how amenable a solution is to humans (hence the notion
of the “Human Window”) adds more depth to how the problems and their
solutions can and should be presented. This book is also helpful to those
who would like to improve their problem-solving skills. No doubt today’s
young people will soon discover that they are lacking in these basic skills,
and this book will be one resource they can turn to for help practicing and
enhancing their problem-solving abilities. Furthermore, there will be ben-
efits from developing and maintaining life-long learning skills.
It must be emphasized that this book is not about solving problems
quickly. Skillful problem solving—whether learning to play chess, becom-
ing a competent violinist, or reading this book—requires time. So get ready
to enjoy, learn, benefit, and grow!
Danny Kopec
Merrick, NY
March, 2014
LIST OF FIGURES AND TABLES
List of Figures
List of Tables
Table 1: Classification of Problems ...................................................................28
Table 2: Ranking The Missionaries and Cannibals Problem Solutions
According to the Human Window......................................................44
Table 3: Solution to the 3 Coins Problem ........................................................53
Table 4: Solution to the 6 Coins Problem ........................................................55
Table 5: Solution to The 12 Coins Problem .....................................................57
Table 6: Number of Weighings Required to Find an Odd Coin
Among n Coins in Different Cases .....................................................59
Table 7: Configuration of Coins in the Two Weighings ...................................60
Table 8: Possible Outcomes After the Two Weighings ....................................61
Table 9: Ranking The 12 Coins Problem Solutions According to
the Human Window ............................................................................64
Table 10: Ranking Cryptarithmetic Solutions According to the Human
Window..............................................................................................86
Table 11: Ranking The Red Donkey Puzzle Solutions According to the
Human Window ..............................................................................101
Table 12: Ranking The 15 Puzzle Solutions According to the
Human Window ..............................................................................125
Table 13: Ranking The Knight’s Tour Problem Solutions According to the
Human Window ..............................................................................143
Table 14: The Monty Hall Problem................................................................171
Table 15: Ranking Rubik’s Cube Solutions According to the
Human Window ..............................................................................195
Table 16: Example 1 ........................................................................................211
Table 17: Example 2 ........................................................................................211
Table 18: Problem-Solving Strategies ............................................................234
CHAPTER
1
INTRODUCTION
T
hese days, students have an abundance of technologies available to
help them solve problems —be it in school or in life. Unfortunately,
most students use technology primarily for entertainment and social
networking. As far as using technology for educational purposes is con-
cerned, applications, for the most part, are limited to finding quick answers
or solutions to assignments. In fact, information about almost every subject
is so readily available and accessible that during the past two decades, evi-
dence of students’ efforts to solve problems that require critical thinking
has become somewhat rare.
Problem solving, issue analysis, and decision making (once considered
standard for college graduates) are increasingly becoming the most sought-
after skills in the employment market [1]. Thus, developing these skills will
be helpful not only in education but in employment and other areas of
life as well. However, people are often overwhelmed by complex problems
and tend to get lost in them [2]. A systematic way to teach students how to
understand a problem, using the appropriate techniques according to the
specific problem types, is clearly needed.
The goal of this book is to collect, classify, and study human and machine
solutions to some classic problems that have frequently been posed in
mathematics, computer science, and artificial intelligence (AI). Overall, we
classify and view these problems as AI problems because of their particular
2 • Artificial Intelligence Problems and Their Solutions
characteristics: they are nontrivial, at least for humans; they involve logic;
they may involve search and memory; solutions to these problems involve
certain techniques, such as deduction, inference, solving subproblems, and
pattern recognition, which are applicable and extendable to other prob-
lems; they are by and large well-known and have survived the test of time;
some of these problems have been used as a testbed for AI problem-solving
techniques—for example, The 15 Puzzle, Mastermind, The Knight’s Tour
Problem, The Red Donkey Puzzle, and Cryptarithms; and they are ame-
nable for studying human problem-solving activity. The long-term, higher
goal of our work is the development of a theory for problem solving. The
problems we have chosen for investigation include the following:
return to the square of origin on its last move. It is common for the knight
to start on the square in the lower left corner of the board (known as a1).
7. Mastermind: This is a two-player code-breaking board game where
one of the players (called the code-breaker) has to decode or guess the
code created by the other player (called the code-maker) in at most
10 guesses. This code is represented by a sequence of colored pegs
arranged in a particular order.
8. The Monty Hall Problem: This problem involves guessing which
door out of three has a prize (e.g., a car) behind it. The dilemma lies in
whether to stick with your first choice or switch doors after the game
host tells you which of the three doors does not have the prize behind it.
9. Rubik’s Cube: This popular sliding block puzzle is a three-dimensional
cube composed of small cubes with different colors on each surface.
The goal is to arrange these small cubes so the cube overall has only one
color on each surface.
10. The Prisoner’s Dilemma: Here we consider a set of problems arising
from classical game theory that involves an optimal scheme for how pris-
oners can get a minimal sentence, depending on whether they cooper-
ate or defect in their private confessions.
11. Miscellaneous Problems: We have also chosen five smaller problems
which are in the same genre as the ten problems presented in this book,
but on a smaller scale. The five problems primarily involve developing a
strong graphical abstraction and understanding of the problem, devising
schema, using probability, and logic.
This book focuses on solutions to these classic problems using specific
problem-solving strategies such as search, problem reduction, deduction,
and mathematical formulas. It also examines how people typically try to
solve problems and presents ideas for how to analyze problems and break
them down to make them more manageable and easier to solve.
and use machines to solve problems for us, we must first have a thorough
understanding of how humans think and solve problems.
Much of the inspiration for our work comes from George Polya’s book
How to Solve It. This little book proved groundbreaking and survived the
test of time in helping problem solvers to become more cognizant of their
activities and how they can be more successful. (See Chapter 2 for more
about Polya’s work.)
Allen Newell and Herbert Simon have contributed significantly to
the topic of problem solving and their research is summarized in the
book Human Problem Solving. According to Newell, Shaw, and Simon,
a problem has a set of paths, only one (or several) of which lead(s) to
a desired goal. Finding that correct path(s) is solving the problem. A
problem is also defined as the difference between an existing state and
a desired state [3]. Newell and Simon give several examples of problem
solving, such as solving a maze or crossword puzzle, finding the com-
bination of a safe, and translating one language into another [4]. Their
research includes topics such as representation of an external environ-
ment in an internal form, strategies such as the creation of subgoals and
subproblems to reach a solution, working backward from a goal, and
using heuristics to find the best path to a solution. They also stress the
process of relying on simple abstractions of a problem space as a way to
approach more complex problems.
Cerveny, Garrity, and Sanders discuss two types of problem solving.
One is linear problem solving, which involves performing a sequence of
steps to reach a goal, and the other is concurrent problem solving, which is
iterative in nature and involves comparing the current state with an ideal
state and performing the steps required to reach that ideal state [5].
Gunzelmann and Anderson state that the two important initial steps
to solving a problem are understanding the problem and representing the
problem in an internal form. They also stress the importance of planning
in problem solving. Humans tend to increase the degree of planning if it is
rewarded with faster solutions [6].
Finding the path leading to a goal is sometimes not enough. Due to
constraints such as time, computing power, and other resources, solving a
problem efficiently with optimum resource utilization is necessary. Accord-
ing to Anzai and Simon, several strategies are available for solving a prob-
lem, some more efficient than others. The efficiency of a strategy depends
Introduction • 5
1.4 REFERENCES
2
PROBLEM SOLVING
P
roblem solving is an important skill that helps us in all aspects of life.
Therefore, it is essential that we follow a systematic approach in solv-
ing problems. Polya’s work [1] was groundbreaking because it led to
the development of a five-step sequence for problem solving, which essen-
tially can be universally applied, independent of domain.
2. Develop an Algorithm
Clearly, problem solving without thinking is not very effective. For
example, in chess, we say it is better to play with a plan, even a bad plan,
than no plan at all. We work by the following definition for an algorithm:
“A well-defined, possibly repeating, finite series of steps to
solve a problem.”
Having noted the problem described in the box above, and cou-
pled with a previous experience (also described above), and recalling
that we had seen a youngster once solve a problem with his computer
by simply opening it up and replacing a fan, an idea emerges:
There is a very small (5-inch fan) available that is sometimes
used during hot summer days for quick local cooling. Perhaps that
fan could be used to cool the laptop.
Problem Solving • 9
The little 5-inch fan has been blowing for about 45 minutes, and
the laptop is still working fine. The area on the top left is still hot,
but not as hot as it was before (just using the sense of touch). Does
this mean that the problem is solved?
Does the solution work? Does it work fully? Does it work par-
tially? Now how confident are you that you have solved the problem?
How much more work is necessary to be certain that the problem
has been solved? More than an hour and a half later, the fan solution
seems to be working.
A problem has provided some given data, some unknowns, some condi-
tions, an initial state, and a goal state. The aim is to use the given data to
find the unknowns while moving from the initial to the goal state. During
the initial stages of problem solving, the solver’s goals are to understand the
problem and represent it in an internal form [2].
One of the key steps in facilitating problem understanding is to rep-
resent the problem in a format that clearly presents the various problem
states (stages) of a proposed solution and the transitions between them.
This often reduces the complexity of the problem. Some problems may best
be expressed in a graphical way, such as a diagram or a graphical sketch,
whereas others may be better represented in a search tree format.
An important aspect of knowledge representation is the level of
detail. A knowledge representation can be extensional or intensional. Exten-
sional representations show every step, case, or example, whereas inten-
sional representations are short and implicit—for example, a formula [3].
We need to choose the representation that best represents the problem and
helps us understand and solve it easily.
According to Polya, an important step in understanding a problem is
isolation of the principal parts—that is, the data, the conditions, and the
unknowns in a problem. These are examined individually, in relation to one
another and in relation to the whole problem [1]. Each of these approaches
helps us understand the problem better.
Once we understand the problem, we go on to planning to solve it. It is
a way to manage the complexity of the problem. It is observed that if plan-
ning leads to faster solutions, the degree of planning increases [4].
Problem Solving • 11
■ Deduction
Deduction involves the attempt to reach a conclusion from some facts
that logically follow one another. Often it may involve general information
from which we try to reach a specific conclusion [8].*
Example 1: The famous modus ponens is a common example:
All men are mortal. Socrates was a man. Therefore, Socrates was mortal.
Example 2: There was a burglary at 365 85th Street, Apt. 4B, between
4:00 and 6:00 pm. John Stealer was the only person seen (by security cam-
era) to enter and leave that apartment between those hours. Thus, it is logi-
cal to assume (by deduction) that John Stealer was the burglar.
Example 3: In medicine, we use deductions to determine what disease
is afflicting a patient. For example, if a patient has a fever, headache, and
sore throat, it would probably be determined that she has the flu because
she has “flulike” symptoms.
■ Abduction
Abduction is an attempt to make a deduction that is not sound. This is
discussed in John Sowa’s book Conceptual Structures. He gives this example:
Example 1: All Quakers are pacifists. Richard Nixon was a Quaker.
Modus ponens would suggest that Nixon was a pacifist. (This is not neces-
sarily true.)
Example 2: Chocolate is the food of love. I am in love. Hence, the
chocolate I ate made me fall in love.
Example 3: Smoking causes cancer. Tom has cancer. Hence, Tom was
a smoker.
■ Empirical
The term empirical is often used with the terms data and evidence—
for example, “empirical data suggest” or “empirical evidence shows.” This
refers to the data or evidence that is available or has been observed.
2.2.1 Heuristics
One of the most important ideas that has come out of Polya’s work is
the notion of heuristics or “rules of thumb.” In effect, heuristics are a very
powerful problem-solving technique that are used universally. That’s why
we think it deserves its own section. Judea Pearl considered this topic so
important that he wrote an entire book about it [10]. When one consid-
ers how we go through our daily lives, it is apparent that we are indeed a
Problem Solving • 19
1. Look for a simpler, related problem. This will no doubt lead to a bet-
ter understanding of the problem itself.
2. Work backward from specific to general. That is, take the facts
to try to deduce what the nature of the problem is. In AI, this is called
backward chaining.
3. Word forward from general to specific. In essence, we are trying
to use generalizations to reach a specific conclusion. For example,
say we encounter one bad student in a school. Then we encounter
several bad students in the school. Hence, all the students we have
encountered are bad. So when we encounter a new student in that
school, we will probably assume that he or she is a bad student. Of
course, this reasoning is unsound, and it can lead to uncalled-for
prejudices.
4. Narrow the condition. See if the problem can be understood better
and solved if the conditions are more restrictive.
5. Widen the conditions to see if that will make the problem easier
to understand and solve. Methods #4 and # 5 may help in problem
comprehension.
6. See if there is a counterexample that will disprove your hypoth-
esis for a solution.
7. Change the conceptual mode. This is akin to incubation. See if you
can look at the problem from a different perspective. This may include
restating the problem, drawing diagrams, or choosing alternative repre-
sentations.
8. Try to approximate a proposed answer. It is always a good idea to
determine if you are in the “right ballpark.”
9. Consider if all the data have been used. It is usually a good idea to
see how different data affects a solution.
10. Look for patterns. Patterns can lend insight to problem
solutions.
22 • Artificial Intelligence Problems and Their Solutions
well one can understand it. Although these criteria assess how well a solu-
tion fits within the Human Window, executability and comprehensibility
are not necessarily dependent on each other. For example, some solutions
to problems can be executed but not necessarily understood. Other types
of solutions may be easy for people to understand, but they may be unable
to execute them.
Along with the above criteria, it is also important to take into consider-
ation the level of detail of a solution to a complex problem in terms of its
knowledge representation and determine whether or not it is extensional
(explicit, detailed, and long) or intensional (implicit, short, and compact).
Extensional representations will usually show every case, every example,
of some information, while intensional representations will often be short
(e.g., a formula or an expression that represents some information).
This book presents solutions to the chosen problems that include sec-
tions on the Human Window for each. In this section, various human solu-
tions will be compared based on a set of Human Window criteria.
Kopec has addressed several of the selected problems in his courses and
has accumulated a number of solutions and resources for their study and
solution. For each of the above complex problems, we have found and ana-
lyzed solutions that have already been developed. Among those solutions,
we have ranked each of them based on our assessment of how they meet the
above criteria (see Section 2). Using these justifications and our opinion, we
have evaluated solutions that may be considered the “Most Human Win-
dow Compatible (MHWC)” and the “Least Human Window Compatible
(LHWC)” for each complex problem. We have also attempted to find the
solutions to the problems that can be deemed the “best” for a machine by
evaluating the runtime and space efficiency of specific algorithms. Finally,
Christopher Pileggi has also attempted to determine the best way to repre-
sent these solutions.
We look at the problem solutions from these points of view:
1. Intensional versus extensional solutions
2. Choice of knowledge representation
3. Suitability in terms of meeting the constraints of the Human Window
(i.e., correctness, grain size, executability, and comprehensibility)
4. Problem-solving method
5. Flexibility
24 • Artificial Intelligence Problems and Their Solutions
6. Mode of conveyance
7. Possible optimality
Finding the most and least Human Window–compatible solutions for
complex problems based on these factors can be beneficial in a number of
ways. For example, finding the best and most suitable solution for humans
can be very beneficial to the study and understanding of problem solving.
The same can be said for finding the optimal solution for a machine prob-
lem. Not only will these solutions apply to the problems they are meant for,
but they may also provide a gateway to solving other human and computa-
tional problems. They can also be used as effective teaching tools.
For each complex problem in the book, we ranked the solutions under
consideration based on the following criteria:
Intensional versus Extensional: The solution to a problem will fall
under the category of being either intensional or extensional. An exten-
sional solution is one that can be explicit, detailed, and usually very long,
while an intensional solution is one that is usually implicit, short, and com-
pact. We indicate whether a solution is extensional or intensional.
Intensionality/Extensionality: Although determining whether a
solution is intensional or extensional is imperative, that doesn’t make the
category black and white. An intensional solution can be measured on
how intensional it is, and an extensional solution can be measured on how
extensional it is. For example, consider two extensional solutions to The
Missionaries and Cannibals Problem: a graph with images and a table with
directions. The graph with images can be considered as more extensional
than the table. As a matter of fact, we can say a solution is even more exten-
sional if it were, for example, to involve watching the missionaries and can-
nibals crossing the riverbank in person. We will give each solution a rank
between 1 and 10 to rate how intensional or extensional a solution is, with
10 being the highest level of intensionality or extensionality.
Choice of Knowledge Representation: When analyzing and ranking
solutions to identify which is considered “most suitable,” it is important to
Problem Solving • 25
number of possible steps. Not only does this reduce the problem size, but it
also tells us what the best possible solution may entail. We indicate whether
or not a solution is optimal.
Along with these rankings, each of these 10 problems is ranked on two
additional factors:
Difficulty Level: This measures how difficult we perceive each prob-
lem to be based on our study of its solutions. The rating is based on how
difficult we find the problems after attempting to solve them and how dif-
ficult we feel others would find them. Each solution is ranked from 1 to 10,
with 10 meaning it is very difficult.
Complexity: Not only is it important to measure how easy or hard it
is for a person to understand a solution, but it also important to measure
how easy or hard it is for a machine. Each problem’s complexity of the best
machine solution is specified in terms of Big-Oh notation.
2.5 CLASSIFICATION
2.6 REFERENCES
1. Polya, G. (1945). How to Solve It, 2nd ed. Princeton, NJ: Princeton University
Press.
2. Burton, L., and Burton, M. (1980). “Problems and Puzzles.” For the Learning
of Mathematics (1) 2: 20–23. Published by: FLM Publishing Association. Stable
http://www.jstor.org/stable/40247710. Accessed on December 23, 2012.
3. Lucci, S., and Kopec, D. (2013). Artificial Intelligence in the 21st Century.
Dulles, Virginia: Mercury Learning, Inc.
4. Gunzelmann, G., and Anderson, J.R. (2002). Problem Solving: Increased Plan-
ning with Practice. Cognitive Systems Research 4 (2003) 57–76.
5. Minsky, M. (1960). Steps Toward Artificial Intelligence. In Computers and
Thought, (Eds. E. Feigenbaum and J. Feldman), McGraw-Hill, New York,
pp. 406–450.
6. Newell, A., and Simon, H.A. (1972). Human Problem Solving. Englewood
Cliffs, NJ: Prentice-Hall.
7. Unterrainer, J.M., and Owen, A.M. (2006). “Planning and Problem Solving:
From Neuropsychology to Functional Neuroimaging.” Journal of Physiology—
Paris 99: 308–317.
Problem Solving • 29
8. Jonathan St. Evans, B.T., Newstead, S.E., and Byrne, Ruth M.J. (1993). Human
Reasoning: The Psychology of Deduction, Hove, England: Lawrence Erlbaum
Associates.
9. Kopec, D. (1983). Human and Machine Representations of Knowledge. (PhD
thesis) Edinburgh, Scotland: University of Edinburgh.
10. Pearl, J. (1984). Heuristics: Intelligent Search Strategies for Computer Problem
Solving. Reading, MA: Addison-Wesley.
CHAPTER
3
THE MISSIONARIES AND
CANNIBALS PROBLEM
3.1 BACKGROUND
objects optimally (in the least number of trips) while satisfying some con-
straints.
Around the thirteenth century, The Jealous Husbands Problem became
popular throughout northern Europe. The problem involved husbands and
wives as the entities, with the restriction being that the husbands were not
allowed to outnumber the wives on either bank [2]. By the end of the nine-
teenth century, the problem had a revival and became known as The Mis-
sionaries and Cannibals Problem. The rules were exactly the same as The
Jealous Husbands Problem, but wives were replaced with missionaries and
the husbands were replaced with cannibals [3].
Today, The Missionaries and Cannibals Problem is widely used in the
field of artificial intelligence. It is considered an important problem for
several reasons. One is because it is an example of a toy problem, which is a
problem that seems insufficient and not worth studying or solving but helps
explain a more general problem-solving technique. Another is because of
its use in the study of problem representation. It is, as computer scien-
tist Saul Amarel pointed out, a prime example of the fact that “the choice
of appropriate representations is capable of having spectacular effects on
problem-solving efficiency” [4].
On the whole, The Missionaries and Cannibals Problem is a relatively
simple problem. Any solution is optimal if it can move all six missionaries
and cannibals to the opposite bank in 11 steps while adhering to the con-
straints of the problem. From analyzing the problem, it can be concluded
that there are four ways to achieve the goal state in 11 steps.
The problem is stated as follows: Given three missionaries and three
cannibals on the West bank of a river, find a way to safely transport every-
one to the other side of the river. The constraints on the problem are:
MMM
CCC
In this figure, the three boxes represent the West bank, the river, and
the East bank, respectively. M stands for missionary, and C stands for
cannibal.
Since the boat is initially stationary, it is not shown. When the boat is in
motion, it can be represented by an arrow that shows in which direction the
boat is moving. Thus, the following figure represents two cannibals being
transported from the West bank of the river to the East bank:
MMM CC
C
MMM
CCC
MMM CC
C
For example, 331 represents the initial state on the West bank with
three missionaries, three cannibals, and a boat. Similarly, the state at the
West bank after transporting two cannibals to the other side can be repre-
sented as 310.
The transition can be shown as:
331 310
It is clear that the first representation is more extensional when com-
pared to the second one. One could use a verbal description or use a formal
notation [6] to describe the states, the moves, and the transition between
the moves, but it is quite apparent that the graphical notation is more trans-
parent and facilitates visualization of states of the problem.
From the initial state, it may seem there are many possible moves.
However, when one delves deeper and considers the constraints of the
problem, it can be seen that two entities must be in the boat to get the
boat back to the West bank. In addition, to avoid the constraint of cannibals
outnumbering the missionaries, either two cannibals or one missionary and
one cannibal can be transported on the first move. Further moves that lead
to safe states are shown in Figure 3.
3.3 SOLUTION
One of the ways to represent this problem and its various moves is in
the search tree format, as shown in Figure 3. A minimum of eleven moves
are required to reach the goal state.
Yet another way of representing the solution is a state transition dia-
gram (Figure 4). The boxes on the left side depict all the safe states on the
West bank, and the boxes on the right side depict the corresponding states
on the East bank. Only states that are safe for both sides of the river are
shown. The arrows represent the transition from one state to another as
well as the direction of the boat.
The moves represented in Figure 4 can also be translated to a problem
state space matrix, as shown in Figure 5. The two matrices depict the set of
problem states on the two banks of the river. The darker-shaded cells corre-
spond to the unsafe states where the cannibals outnumber the missionaries,
The Missionaries and Cannibals Problem • 35
W E Initial Goal
MMM MMM
CCC State CCC State
MMM CC MM MC
C CC
MMM C C MM M C
C CC
MMM CC C Sub-goal 1
MMM C CC
MC MM CC
MC MC MC
CC MM MC
Sub-goal 2
CC C MMM
C CC MMM
C C MMM C M MM
C CC
CC MMM MC MM
C CC
MMM
CCC Goal
Initial
M M M C C C
State
1.
M M M C C CC C
State 2
2.C
3.C
State 4 M M M C C C C State 1
4.C
M M M C C C State 3
5.M
M
State 6 M M C C M C
6.M
C
M C M M C C State 5
7.M
M
State 8 C C C M M M
8.C
9.C
State 10 C C M M M C State 7
10.
CC
C 11 M M M C C State 9
.C
C
M M M C C C Goal State
WEST EAST
Initial Initial
Missionaries State Missionaries State
3 0 0 0
2 1
1 2
0 x 3 x
Goal 0 1 2 3 Goal 3 2 1 0
State State
Cannibals Cannibals
and the lighter-shaded cells depict the safe states. The striped cells depict
the states corresponding to the unsafe states on the other side of the river.
For example, having two missionaries and one cannibal on the East bank is
The Missionaries and Cannibals Problem • 37
a safe state per se. However, when you consider the corresponding state on
the West bank, (i.e., one missionary and two cannibals), you know it is an
unsafe state for the West bank, and thus this state is invalid and should be
avoided. Therefore, the solution involves transitioning from the initial state
(cell marked 0) to the goal state (cell marked X).
The moves are numbered and are mentioned in the cell representing
the state after the move is made. The moves made on the West bank (i.e.,
the departing of the boat) are represented by odd numbers in the matrix
labeled WEST, and the moves made on the East bank are represented by
even numbers in the matrix labeled EAST. The solution in matrix form is
shown in Figure 6.
WEST EAST
Initial Initial
Missionaries State Missionaries State
3 3 1 0 0 4 2 0
2 1 6
1 5 2
0 11 9 7 3 x 10 8
Goal 0 1 2 3 Goal 3 2 1 0
State State
Cannibals Cannibals
Initial State
(Source)
3
M
1
Key
Legal State
Illegal State
0 West to East
C East to West
Goal State M No. of Missionaries
0 1 2 3
(Destination) C No. of Cannibals
sionaries from the East bank to the West bank. This property can help us
perform a bidirectional search of the problem and thus reduce the search
by a factor of two.
West East
MMM
CCC
Here is how three students tackled the problem. (The complete solu-
tions are available in Appendix A.)
Student 1:
The student uses a diagram similar to the instructor’s (Figure 9).
The diagram represents the states after every move.
A written explanation of
W E
each move accompanies the
diagram. MMM
1
CCC
The student starts with
two entities on the boat but 2
MM MC MC M and C in the
CC boat
realizes that one has to stay
back and the other has to re- MMM
3 M C Drop C, M leaves
C
turn to fetch other people.
The student starts with an
FIGURE 9 Student 1’s Partial Solution.
M and a C but abandons the
solution after two steps.
The next attempt is made by moving two Cs first but again abandoning
the attempt after three steps.
In the third attempt, two Ms are moved first, but this fails to satisfy the
constraint imposed by the problem in the second move.
The student goes back to the first attempt and tries again, this time
reaching the sixth step and successfully moving one C and one M to the
other side of the river.
The time allotted is over (Figure 10).
40 • Artificial Intelligence Problems and Their Solutions
Conclusion
W E
The student tries the three possible first
MMM
0
CCC
moves, and, after reaching dead ends, he
learns about good and bad moves. By the
MM M and C
1
CC
MC
leave
third attempt, the student has evaluated the
best of the three possible first moves. In the
MMM
2
CC
C M leaves fourth attempt, the student makes this move
and proceeds further, carefully avoiding the
3 MMM CCC CC leaves
moves that violate the problem constraint.
4
MMM
CC C leaves The student has gathered this knowledge
C
from the previous three trial-and-error at-
MM
5 MC
CC
MM leave tempts.
MM The student first tries to understand the
6 MC leave
CC
problem by using the trial-and-error tech-
nique and plans for the next attempt.
FIGURE 10 Student 1’s Solution.
Student 2:
The student uses characters M and C to represent
MMM
individual missionaries and cannibals respectively, and CCC
uses arrows to depict the direction of the boat. MMM
CC
C
No other explicit representation of the moves is MMM
C
CC
shown.
MMM CCC
First, all the cannibals are transferred to the East MMM
CC
bank of the river. C
MM
MC
Then all the cannibals are returned to the West CC
MM
bank, and all the missionaries are brought to the East CC
MC
The student solves the problem in time. It seems FIGURE 11 Student 2’s
she recognizes that one of the subgoals is to separate Solution.
The Missionaries and Cannibals Problem • 41
the Cs from the Ms by moving all the Ms or all the Cs first. However, while
transferring the Ms, some Ms and some Cs sometimes have to be trans-
ferred together to maintain balance to avoid having Cs outnumber Ms. The
student realizes that moving the Cs back to the West bank again is necessary
to get all the Ms on the East bank.
Student 3:
Student 3 uses a tabular format with three columns to represent the
problem and the solution. The first column depicts the state on the West
bank, the second column represents the state
on the East bank, and the third column repre- 3M MC
sents the move. 3C
2M M
The student starts by moving a missionary M
2C C
and a cannibal in the first move and proceeds 3M
to move all the cannibals to the East bank. C 2C
2C
After this, the student skips some steps, 3M 3C
reaches the second to last step, and then the M 2M
last step, and does not show the moves in the C 2C
table. 3M
3C
The last two steps are the exact opposite of
the first two steps (Figure 12). FIGURE 12 Student 3’s Solution.
Conclusion
It may be possible that the student was able to identify that this solution
has time reversal symmetry and thus jumped to the last few steps and was
either trying to figure out or gave up figuring out the steps in between. It
seems there was an attempt to use bidirectional search, as the end states were
mentioned with some steps in the middle missing. It may be possible that
apart from searching from the initial state toward the goal state, the student
was working backward toward the goal.
possible. This is accomplished after the first four moves. However, at least
one cannibal has to return back to fetch the missionaries. Now we can start
moving the missionaries to the other side. The sixth move is extremely im-
portant. It maintains the equilibrium by moving a missionary and a cannibal
to the West bank to get the last of the missionaries from that side in the
seventh move, while also ensuring a safe state on the East bank.
Note that this step seems like it is leading away from the solution (i.e.,
this move causes the distance between the current state and the goal state
to increase) [5]. The next four steps get the remaining cannibals back on
the East bank.
By analysis, it was found that people divide the problem into three or
four major subproblems [5]. It is evident from the solution in Figure 10 that
the first four steps involve moving all the cannibals to the East bank. The
next three steps involve carefully move the cannibals back to retrieve all the
missionaries, while balancing the number of missionaries and cannibals on
either side of the river. Finally, the last four steps again move all the can-
nibals to the East bank.
We can see that the majority of solutions were either table or graphical
representations. This is most likely because this is a problem that involves
visualization, as there is an environment with two kinds of entities interact-
ing with it. Also, graphs and tables help provide visualization that minimizes
the need for descriptions.
Overall, the solutions had mixed rankings for each of their categories.
Some were more executable than comprehensible and some more compre-
hensible than executable. However, those that contained images or graph-
ics generally fit more within the Human Window. It can also be seen that
they have a higher ranking of extensionality as well, while those represented
by text or tables were ranked relatively low. Finally, these solutions used a
graphical/visual representation as their primary problem-solving technique,
while others, especially those represented by tables, used more of a top-
down approach.
Difficulty
2/10
Complexity
O(n)
Key
Grn Sz: Grain Size—How much computation (large) or memory (small) does one need to solve the solution?
Prob. Solv. Mthd: Problem-Solving Method—What method is used in the solution to solve the problem?
Flex: Flexibility—How flexible is this solution (i.e., can this solution be represented in other ways)?
Mode of Conv: Mode of Conveyance—In what ways can this solution be reproduced/replicated?
Opt?: Optimal—Is the solution optimal?
TABLE 2 Ranking The Missionaries and Cannibals Problem Solutions According to the Human Window.
The Missionaries and Cannibals Problem • 45
method of problem solving: the use of subgoals. When you examine this
solution further, you will notice that the first half of the solution is an exact
mirror image of the second half. This shows that when the first half of the
problem is solved, the second half can be solved by replicating the steps for
the first half in reverse and placing the missionaries and cannibals on re-
verse banks. The solution depicts this symmetry by presenting the graph as
a symmetrical image. Finally, this symmetry once again reveals the benefits
of using a bidirectional search to solve this problem. That’s why this is the
MHWC solution, despite the fact that it did not receive the highest overall
ranking on the table.
Start Goal
C ×1 MC C ×2, W C ×2, W MC C ×1
MC MC
MC MC
M ×1, M ×1,
C ×1, W C ×1, W
MC MC C M M C MC MC
C MC MC MC C MC MC C MC MC MC C
M M M M
M ×1, E M ×1, E
MC C ×1, E C ×1, E MC
C MC MC C
M M
C ×2, W C ×2, W
C M M C
C M M C
C M M C
C ×1, E C ×1, E
M M
C MC C
C MC C
M M
M ×2, W M ×2, W
M x1,
C x1, E
MC MC
MC MC MC MC
Key:
M = Missionary W = West Bank
C = Cannibal E = East Bank
For example, M ×1, W
One missionary travels to the west bank
FIGURE 13 The “Symmetric Solution.”
and the rule applied to get to that state. When analyzing the table, a pos-
sible issue that arises with this method is tracing the solution in general. To
fully understand how the solution is carried out, one must either memorize
each rule, which is simply too difficult, or continuously refer back to the
table to find a corresponding rule, which can be very tedious.
The Missionaries and Cannibals Problem • 47
Constraint Rules
Rule
Constraint
No.
1 B(2, 0) iff : (x – 2 ≥ y || x – 2 = 0 in one bank) && (x + 2 ≥ y in the other)
2 B(1, 0) iff : (x – 1 ≥ y || x = 0 in one bank) && (x + 1 ≥ y in the other)
B(1, 1) iff : (x – 1 ≥ y – 1 || x = 0 in one bank) && (x + 1 ≥ y + 1 || x = 0 in
3
the other)
4 B(0, 1) iff : (y – 1 < x || x = 0 in one bank) && (y + 1 ≤ x || y = 0 in the other)
5 B(0, 2) iff : (y – 2 ≤ x || x = 0 in one bank) && (y + 2 ≤ x || x = 0 in the other)
Example
Step State Rule Applied
0 W(0, 0); E(3, 3) (Init)
1 W(1, 1); E(2, 2); B(1, 1) 3
2 W(0, 1); E(3, 2); B(1, 0) 2
………
10 W(2, 2); E(1, 1); B(1, 0) 2
11 W(3, 3); E(0, 0); B(1, 1) 3
3.8 REFERENCES
4
THE 12 COINS PROBLEM
Score
11188
4.1 BACKGROUND
For The 12 Coins Problem in this chapter, given that 1 of the 12 coins
has a different weight, the challenge is to find the odd coin in just three
weighings and also to determine if the coin is heavier or lighter than the
others.
The data given for this problem is:
There is only one odd coin.
The odd coin has a weight different from the others.
The unknowns are:
Which coin is the odd one?
Is the odd coin heavier or lighter than the others?
The constraint is:
Only three weighings are allowed.
means one of the first two coins is odd and the third coin is not odd. In any
case, after the results of first weighing, the 3 coins problem becomes similar
to the “2 coins problem with the standard coin,” and thus the odd coin and
its relative weight can be found in a total of two weighings. A solution to
the 3 coins problem with the coins named A, B, and C is shown in Table 3.
Weighing 1 Weighing 2
Result
A?B A?C
A=C Not possible because one of them is odd
A=B
(Thus, C is A>C C is odd and light
odd)
A<C C is odd and heavy
A=C B is odd and light
A>B
(Thus, A or B A>C A is odd and heavy
is odd)
A<C Not possible because ONLY one of them is odd
A=C B is odd and heavy
A<B
(Thus, A or B A>C Not possible because ONLY one of them is odd
is odd)
A<C A is odd and light
Alternatively, we could take the first 3 coins and solve them in two
weighings like we did for the 3 coins problem. If both groups weigh the
same, we know the fourth coin is odd, and one more weighing with one of
the known good coins can tell us if the fourth coin is overweight or under-
weight. Thus, the 4 coins problem can be solved in three weighings.
This problem helps us conclude that dividing coins into groups of three
gives us more information in the first weighing, as compared to dividing
into groups of two—the information about the group that has good coins
only. This is because after the first weighing, we know that either the first
two groups or the third one have all good coins, thus separating the good
coins from the groups containing the odd coin, and thereby reducing the
problem into one with fewer coins.
If we try to solve the 6 coins problem with the knowledge gained from
the previous two problems, we can proceed as follows: Divide the coins to
three groups of 2 coins. After comparing the first two groups, we know the
odd coin is in one of first two groups if they do not weigh the same or that
the odd coin is in the third group if the first two groups weigh the same in
the first weighing.
In either case, one more weighing of the odd (or possibly odd) group
with one of the good group(s) will tell if the odd coin is heavy or light, and
the third weighing will help identify the odd coin in the odd group (Table 4).
Weighing 1 Weighing 2
Weighing 3 Result
AB ? CD AB ? EF
Not possible
AB = EF because ONLY
one of them is odd
Not possible because ONLY
E=F
AB = CD one of them is odd
AB > EF
E>F F is odd and light
(E or F is
E<F E is odd and light
odd)
Not possible because ONLY
E=F
one of them is odd
AB < EF
E>F E is odd and heavy
E<F F is odd and heavy
The 12 Coins Problem • 55
with the other two groups in two weighings, we know the odd group and
the relative weight of the odd coin. Therefore, the problem is reduced to a
3 coins problem when the relative weight of the odd coin is known. Hence,
one more weighing gives us the odd coin.
Alternatively, we could consider the 3 coins in each of the three groups
as one big coin. The problem could then be reduced to a 3 coins problem,
and after two weighings, we know if the three groups or the big coin is odd
and if it is heavy or light. Thus, now we know the group of 3 coins contain-
ing the actual odd coin. This problem is thus reduced to a 3 coins problem
where we know that the odd coin is heavy or light, and thus one weigh-
ing is enough to find the odd coin. This technique is known as recursion,
where a problem is continuously broken down to a subproblem that, when
it reaches the elementary or base case, can be solved directly.
We can conclude that as the number of coins increases, we need to
compare as many coins as possible in the first two weighings to reduce the
problem to one that is as small as possible. We have just seen how a 9 coins
problem was reduced to a 3 coins problem after two weighings.
4.3 SOLUTION
Weighing 1
Weighing 2 Weighing 3 Result
ABCD ? EFGH
Not possible because one of
A=L
them is odd
ABC = IJK
A>L L is odd and light
A<L L is odd and heavy
I=J K is odd and light
ABCD = EFGH
ABC > IJK I>J J is odd and light
I<J I is odd and light
I=J K is odd and heavy
ABC < IJK I>J I is odd and heavy
I<J J is odd and heavy
The 12 Coins Problem • 57
In this solution, the 12 coins are divided into three groups of 4 coins
each. In the first weighing, we know either that the third group of coins,
which has not yet been weighed, has the odd coin or that one of the first
two groups has the odd coin. In the first case, the problem is reduced to a
4 coins problem. By removing one coin from this group, the problem can
be solved as a 3 coins problem in two more weighings. If that fourth coin
that was omitted is found to be odd (by the second weighing), it can be
weighed against a known good coin to check if it is heavy or light in the
fourth weighing.
In the second case, we know the relative weights between the first two
groups and can use this knowledge for the next weighing. We then divide
58 • Artificial Intelligence Problems and Their Solutions
the heavier group into 2 coins each and place it on either side of the scale.
We then take 2 coins from the lighter group and place one on either side
of the scale and conduct the second weighing. This would reduce the num-
ber suspect odd coins to 3 possible coins if the scales do not balance or 2
possible coins (the remaining 2 from the lighter group) if the scales do bal-
ance. In any case, one more weighing will suffice to detect the odd coin.
This solution, though correct, cannot be extended to any number of coins.
We can generalize The 12 Coins Problem to an n coins problem. It
was found that the number of weighings required to find an odd coin
among n coins can be deduced from the following formulas developed by
Bennet Manvel in his article “Counterfeit Coin Problems” in Mathematics
Magazine:
An underweight coin in a set of k coins can be found in [log 3 k] weighings.
If we know only that the counterfeit coin is a different weight, then
⎡log 3 (2k + 3)⎤ weighings are required.
⎡log 3 (2k + 1)⎤ weighings are required if a standard coin is provided.
In Table 6, we tabulated the number of weighings for several n coin
problems using the formulas for the three cases mentioned above.
3 1 2 2
4 2 2 3
6 2 3 3
9 2 3 3
11 3 3 3
12 3 3 3
The 12 Coins Problem • 59
13 3 3 4
39 4 4 4
40 4 4 5
120 5 5 5
* Please note that [x] means the “ceiling” of x, or the smallest integer greater than or equal to
x, where x is a real number [1].
TABLE 6 Number of Weighings Required to Find an Odd Coin Among n Coins in Different Cases.
7.00
‘N’ coins problem
6.00
5.00
No. of weighings
4.00
3.00
No. of weighings = log3(k)
2.00
No. of weighings = log3(2k+1)
1.00
No. of weighings = log3(2k+3)
0.00
1 3 9 27 81 243
No. of coins
Divide each of the three groups into a main subgroup of 3 coins and
then 1 coin.
Place the first two groups of 4 coins on either side of the scale and note
the results. This is the first weighing.
Then, rotate the main subgroups—in other words, remove the main
subgroup of the first group from the left pan of the scale, move the main
subgroup of the second group from the right pan to the left, and keep the
main subgroup of the third group on the right pan of the scale. Keep the
single coins from the first two groups as they are on the scale. This is the
second weighing.
Weighing 1 (W1) A, B, C, D E, F, G, H
Weighing 2 (W2) E, F, G, D I, J, K, H
The key aspect of this solution is that it tries to maximize the amount
of information gained in the least number of weighings. In the first two
weighings, 11 out of the 12 coins are weighed. The weighings are then con-
figured in such a way so that after two weighings, the problem is reduced to
62 • Artificial Intelligence Problems and Their Solutions
a smaller problem that can be solved in just one more weighing, depending
on the nine possible results. Also, we can leverage the information gained
from the previous two weighings in the last weighing.
According to this solution, to solve a (3n – 3)/2 coins problem in general,
the following steps must be followed [2]:
Divide the coins into three equal main groups. Each is to be divided
into (n – 1) subgroups of 3n-2, 3n-3, . . . , 30 coins.
Place the first two main groups on each side of the scale. This is the first
weighing.
Rotate only the largest subgroups, as described above in The 12 Coins
Problem solution. This is the second weighing.
If the condition of the balance changes, as seen in the last six cases
of The 12 Coins Problem solution above, the subgroup containing the
odd coin will be identified, and the problem will be reduced to a smaller
problem.
Continue the rotation of the next largest subgroups until there is a
change in the condition of the balance or until there is only one coin on
each side of the scale. Then rotate them and the odd coin, and its relative
weight will be found.
the relative weights of two groups of coins compared in the first weighing
to narrow down the number of possible odd coins.
From the analysis of The 12 Coins Problem, by reducing it into smaller
problems, we learn more about the problem and get clues about how to
solve the original problem. Also, decomposing a bigger problem into small
parts and solving the smaller problems recursively helps to solve the bigger
problem. We have seen that problem reduction and recursion techniques
were useful in solving The 12 Coins Problem.
When analyzing the solutions (Table 9), we can see some similarities in
their rankings. First, note that each of them is extensional. The solutions we
found are specific to The 12 Coins Problem. Since the solution is relatively
small (three weighings), any method can depict the problem in its entirety.
If the table contained a solution to the general n coins problem, however, it
would most likely be classified as intensional.
Overall, their rankings of the solutions’ extensionality are mixed. Those
that used actual images depicting coins and scales were generally ranked
higher, while those represented by text were ranked lower. However, not
many of the solutions found used images as a means of representation.
The choices of knowledge representation used for the solutions are a
mix between tables and text. The text solutions give a general description
about each possible outcome for all three weighings. The tables simplify
these explanations with the use and organization of symbols. In general,
each solution uses the three weighings method similarly and emphasizes
the subproblems generated by it.
The rankings pertaining to how the solutions fit into the Human Win-
dow are mixed as well. In general, each of the solutions was given a high
ranking for executability. Overall, it is easy to follow the steps of the three
weighings regardless of the representation used. The comprehensibility
of the solutions, however, was mixed. Those that used a text representa-
tion were generally ranked lower, while those represented by tables were
ranked higher. Finally, it can be noted that each of the solutions used the
same general problem-solving techniques, which entail looking for subgoals
by employing using visual representations.
64 • Artificial Intelligence Problems and Their Solutions
Difficulty
3/10
Complex
O(n(log 3n))
Int Prob.
Inlty/ Grn Mode of
Name or Rep. HW? Corr? Exec Compr Solv. Flex Opt? Tot
Exlty Sz Conv
Ext? Mthd
Txt Vis. Rep.;
B&Y Ext. 2/10 Y Y Ideal 8/10 8/10 8/10 Txt Editor Y 26/40
Desc Subgoals
Txt Vis. Rep.; Txt Editor;
Duncanson Ext. 4/10 Y Y Ideal 7/10 6/10 9/10 Y 26/40
Desc Subgoals Hand
Tble Mkr;
Vis. Rep.;
FA Ext. 6/10 Tble Y Y Ideal 10/10 7/10 7/10 Txt Editor; Y 30/40
Subgoals
Hand
Generic Tbl. Rep.; Tbl Mkr;
Ext. 7/10 Tble Y Y Ideal 10/10 8/10 8/10 Y 33/40
Table Subgoals Hand
Graphic
Logically Txt Vis. Rep.;
Ext. 3/10 Y Y Small 7/10 5/10 5/10 Img Mkr; Y 20/40
Enumerated Desc Subgoals
Hand
Logic Vis. Rep.;
LogicFlow Ext. 5/10 Y Y Small 9/10 6/10 7/10 Img Mkr Y 27/40
Dgrm Subgoals
Tbl Mkr;
Txt; Vis. Rep.;
Poskitt Ext. 7/10 Y Y Ideal 8/10 5/10 7/10 Txt Editor; Y 27/40
Tble Subgoals
Hand
Key
TABLE 9 Ranking The 12 Coins Problem Solutions According to the Human Window.
Weighing 1
ABCD? Weighing 2 Weighing 3 Result
EFGH
A=L Not possible as one of them is odd
ABC = IJK A>L L is odd and light
A<L L is odd and heavy
used to show the possible outcomes the scale may produce during any of
the three weighings, with each column representing a different weighing.
These outcomes contain letters that represent the coins and a conditional
operator that represents the result of the weighing. The coins (letters) that
are grouped together are those present on a specific side of the scale. The
last column indicates the result of the third weighing, thus concluding
whether a coin is heavy or light, or if the weighing is impossible.
This solution is comprehensible because it is concise and the columns
in the table organize the solution well. This solution is also highly execut-
able. When the result of the first weighing is found, the remaining possible
results for the second weighing are directly adjacent to that result in the
next column. This adjacency is also present for the second and third weigh-
ings. This makes it possible for the solution to be found easily and quickly,
and it reduces the information needed to be found in the table overall.
Although the solution is comprehensible, the overall comprehensibility
could be improved if a small picture of the actual scale were present next to
each possible outcome to show if the scale is balanced or not. Additionally,
it could be improved even further if the letters had circles around them,
which would better indicate that they are in fact representing coins.
Finally, the groups are indicated as being on the left or right side of the
scale by separation using a conditional operator. Although this works for the
“Generic Table Solution,” it may not work in this type of representation.
• Coin Groups: {X1, X2, X3, X4}; {Y1, Y2, Y3, Y4}; {Z1, Z2, Z3, Z4}
• Weigh X1-X2-X3-X4 against Y1-Y2-Y3-Y4.
• Case 1
• 1st weighing: If X1-X2-X3-X4 = Y1-Y2-Y3-Y4
The counterfeit must be in group Z. Takeany of the X or Y coins as a control coin (i.e., X1).
Weigh Z1+Z2 against Z3+X1.
Case 1.1
2nd weighing: Z1+Z2 >Z3+X1.
Z1 or Z2 is heavy or Z3 is light. Weigh Z1 against Z2.
(or if Z1+Z2 < Z3+X1, substitute heavy for light and vice versa in the following.)
♦ Case 1.1.1
♦ 3rd weighing: Z1 = Z2
Z3 is light.
♦ Case 1.1.2
♦ 3rd weighing: Z1 > Z2
Z1 is heavy.
♦ Case 1.1.3
♦ 3rd weighing: Z1 < Z2
Z2 is heavy.
Case 1.2
2nd weighing: Z1+Z2 = Z3+X1
Z4 must be the counterfeit.
Weigh it against any of the control coins to determine whether it is heavy or
light.(i.e., X1)
♦ Case 1.2.1
♦ 3rd weighing: Z4 < X1
Z4 is light.
♦ Case 1.2.2
♦ 3rd weighing: Z4 > X1
Z4 is heavy.
68 • Artificial Intelligence Problems and Their Solutions
• Case 2
• 1st weighing: X1-X2-X3-X4 < Y1-Y2-Y3-Y4 (analogous holds if X1-X2-X3-X4 >
Y1-Y2-Y3-Y4; switch heavy for light and vice versa)
One of the Xs is lighter than the rest, or one of the Ys is heavier than the rest.
All the Zs can be taken as control coins
Weigh X1-X2-Y1-Y2 against X3-Y3-Z1-Z2.
Case 2.1
2nd weighing: X1-X2-Y1-Y2 > X3-Y3-Z1-Z2
Y1 or Y2 is heavy, or X3 is light.
Weigh Y1 against Y2.
♦ Case 2.1.1
♦ 3rd weighing: Y1 > Y2
Y1 is heavy.
♦ Case 2.1.2
♦ 3rd weighing: Y1 < Y2
Y2 is heavy.
♦ Case 2.1.3
♦ 3rd weighing: Y1 = Y2
X3 is light.
Case 2.2
2nd weighing: X1-X2-Y1-Y2 = X3-Y3-Z1-Z2
X4 is light or Y4 is heavy. Weigh X4 against Z1.
♦ Case 2.2.1
♦ 3rd weighing: X4 < Z1
X4 is light.
♦ Case 2.2.2
♦ 3rd weighing: X4 = Z1
Y4 is heavy.
Score
11188
4.8 REFERENCES
5
CRYPTARITHMS
S E N D
+ M O R E
M O N E Y
FIGURE 20 The Send More Money Problem.
5.1 BACKGROUND
is also an alphametic, since the words in the puzzle form a sensible phrase
SEND MORE MONEY (Figure 20). One of the notable characteristics of
this problem is the extra digit in the sum (i.e., the M), because it is an
important clue. Another is that some of the letters, such as M, E, and N, are
repeated, so the sooner they are deciphered, the more quickly the problem
can be solved.
S E N D
+ M O R E
M O N E Y
Problem 2:
DONALD + GERALD = ROBERT (Clue: D = 5)
This is another well-known problem, and it has been the subject of
Newell and Simon’s study of human problem solving using cryptarithmetic.
D O N A L D
+ G E R A L D
R O B E R T
Note the hint that D = 5. This very helpful in finding more information
about all the variables connected to D by the different constraints—namely,
the T, the carryover to the second column, G, and R.
5.3 SOLUTION
Problem 1:
SEND + MORE = MONEY
Here is a solution that is very similar to many others available online.
Since the sum has one digit more than the two numbers being added, we
choose to start solving the problem from the left side. We will refer to
the columns as first, second, third, and so on, starting from the right side. As
we begin to find clues to the solution, we keep adding them to a Knowledge
Table and refer to it to obtain additional clues.
74 • Artificial Intelligence Problems and Their Solutions
c5 c4 c3 c2
S E N D
+ M O R E
M O N E Y
FIGURE 21 Step 1.
Deductions
c5 = 1 → c4 + S + 1 greater than 9 1 c4 c3 c2
S E N D
S + 1 greater than 9 → S = 8 if c4 = 1 + 1 O R E
or S = 9 if c4 = 0
1 O N E Y
In both cases above, S = 8 or S = 9 → O = 0
Knowledge Unknowns 1 c4 c3 c2
Table S, E, N, D, R, Y
c2, c3, c4 S E N D
c5 = 1
M=1 + 1 0 R E
Remaining Numbers
O=0 2, 3, 4, 5, 6, 7, 8, 9 1 0 N E Y
S = 8 if c4 = 1 or
S = 9 if c4 = 0
FIGURE 22 Step 2.
FIGURE 23 Step 3.
76 • Artificial Intelligence Problems and Their Solutions
Deductions
1 0 1 c2
c3 = 1 → c2 + N + R = E +10
9 E N D
E + 1 = N → c2 + (E + 1 ) + R = E + 10 + 1 0 R E
→ c2 + R = 9
1 0 N E Y
If c2 = 0, R = 9, which is not possible
because S = 0 → c2 = 1
c2 = 1 → R = 8
Knowledge Table
M=1 Unknowns 1 0 1 1
O=0 E, N, D, Y 9 E N D
S=9
c4 = 0 + 1 0 8 E
c3 = 1 1 0 N E Y
Remaining Numbers
E+1=N
E<9 2, 3, 4, 5, 6, 7
c2 = 1
R=8
FIGURE 24 Step 4.
Cryptarithms • 77
Deductions
c1 = 1 → D + E = Y > 10
If E = 5, D = 7, Y = 2, and N = 6
6 + 7 = 13
This is the solution.
Knowledge Table
M=1
O=0
Unknowns
S=9 1 0 1 1
c4 = 0 9 5 6 7
c3 = 1
Remaining Numbers
E+1=N + 1 0 8 5
E<9 3, 4
1 0 6 5 2
c2 = 1
R=8
E= 5
N=6
D= 7
Y =2
FIGURE 25 Step 5.
78 • Artificial Intelligence Problems and Their Solutions
c6 c5 c4 c3 c2
D O N A L D
+ G E R A L D
R O B E R T
Deductions
D = 5 → T = 0 and c2 = 1 c6 c5 c4 c3 1
5 O N A L D
c2 = 1 → 1 + 2L = R + c3
+ G E R A L D
1+ 2L = R + c3 → 1 + 2L = R R O B E R T
→ R is odd or 1+ 2L=R + 10
Knowledge Table Unknowns
D=5 O, N, A, L, G, E, R, B c6 c5 c4 c3 1
T=0
c2 = 1 c3, c4, c5, c6 5 O N A L 5
R is odd + G E R A L 5
2L + 1 = R or
Remaining Numbers R O B E R 0
2L + 1 = R + 10
1, 2, 3, 4, 6, 7, 8, 9
FIGURE 26 Step 1.
Cryptarithms • 79
FIGURE 27 Step 2.
Deduction
1 1 c4 c3 1
c3 + A + A = 9 or c3 + A + A = 19 → c3 = 1
If c4 = 1 → A = 9 5 O N A L 5
If c4 = 0 → A = 4 + G 9 R A L 5
E = 9 → A = 4 and c4 = 0 R O B 9 R 0
FIGURE 28 Step 3.
80 • Artificial Intelligence Problems and Their Solutions
Deduction
1+5+G=R→6+G=R
1 1 0 1 1
6 + G = R and R is odd → R = 7 or 9
5 O N 4 L 5
E=9→R=7
R=7→G=1 + G 9 7 4 L 5
R O B 9 7 0
FIGURE 29 Step 4.
Deduction
N + 7 = B and c5 = 1 → N + 7 = B + 10 1 1 0 1 1
N + 7 = B + 10 → N = B + 3 5 O N 4 L 5
N = B + 3 → Of the remaining numbers, only N=
6 and B = 3 satisfy the equation. + 1 9 7 4 L 5
7 O B 9 R 0
Knowledge Table Unknowns
D=5
O, L
T=0
c2 = 1 1 1 0 1 1
R is odd 5 O 6 4 L 5
2L + 1 = R or Remaining Numbers
2L + 1 = R + 10 + 1 9 7 4 L 5
2, 8
E=9
7 O 3 9 7 0
c5 = 1, c6 = 1
c3 = 1, c4 = 0
A=4
R=7
G=1
N=6
B=3
FIGURE 30 Step 5.
Now we also have some new data for the second column: 1 + L + L = 7
(see Figure 31). Because there is a carryover to the third column, L = 8
makes the sum = 1 + 8 + 8 = 17. The only remaining digit is 2, and the
remaining alphabet is O. Thus, O = 2.
Knowledge Table
D=5 Deduction
T=0 1 1 0 1 1
1 + L + L = 17 → L = 8
c2 = 1 5 O 6 4 L 5
R is odd L=8→O=2
2L + 1 = R or + 1 9 7 4 L 5
2L + 1 = R + 10
7 O 3 9 7 0
E=9 Unknowns
c5 = 1, c6= 1
c3 = 1, c4 = 0 The solution is as below:
A=4
R=7 Remaining Numbers 1 1 0 1 1
G=1 5 2 6 4 8 5
N=6
+ 1 9 7 4 8 5
B=3
L=8 7 2 3 9 7 0
O=2
FIGURE 31 Step 6.
82 • Artificial Intelligence Problems and Their Solutions
It is evident from the above two solutions that we also have computed
the value of the carryovers, which are also known as auxiliary variables.
Even though auxiliary variables are not directly a part of the solution, they
help in the problem-solving process.
Let us consider Problem 1: SEND + MORE = MONEY.
The variables are S, E, N, D, M, O, R, and Y.
The domain for these variables is 0 to 9.
The auxiliary variables are c1, c2, c3, and c4 (the carryovers).
The domain for auxiliary variables is 0, 1.
The constraints are as follows:
All the variables represent different numbers.
The numbers do not start with digit 0.
S = c4
c3 + S + M = O + 10*c4
c2 + E + O = N + 10*c3
c1 + N + R = E + 10*c2
D + M = Y + 10*c1
If we conduct an exhaustive search for the solution through the prob-
lem state space, we soon realize that it is a herculean task, because if a
problem consists of 10 different variables, there are 10! = 3,628,800 pos-
sible assignments [4]. However, as observed previously, if we can decipher
some of the variables using the clues inherent in the problem, such as an
extra digit in the sum or a 0 or 9, we can reduce the number of possible
combinations—but only to a certain extent.
Alternatively, we can formulate the problem as a search tree by consider-
ing one of the values found initially as the initial state and the goal state, being
the situation where the value of every variable in the solution is known [4].
We can also divide the problem into subproblems. In this case, we can think
of a column as a subproblem and consider solving one subproblem at a
time by computing the values of the variables in that column. However, it is
futile to consider a column in isolation because the carryovers from the sum
in one column affect the sum in the next column, and thus the columns are
connected to each other. This relationship between the columns—or, more
Cryptarithms • 83
specifically, between the variables—is evident from the list of constraints and
can be more clearly seen via a constraint hypergraph, which George Luger
developed for this problem [4]. Therefore, we have to consider the con-
straints that connect one column to the other. If we look closely, it is the aux-
iliary variables (i.e., the carryovers) that connect two columns. Fortunately,
the domain of these auxiliary variables is very small, because the values are
either 1 or 0. Thus, if we correctly identify these auxiliary variables, we may
be able to prune the search tree and reduce the search effort and time. Addi-
tionally, we can assume one of the legal values for the auxiliary variable and
find the values for the remaining variables in a particular column.
This heuristic, which involves considering the variables’ fewest possible
values, is called the minimum remaining values (MRV) heuristic [4]. Thus,
after applying the “generate and test technique” to the variables with MRV,
the domain of the other variables in the column is also reduced. We also
consider the second possible value for the auxiliary values and compare the
resulting domains of the variables in the column.
For example, in Problem 1, consider column 4 after substituting M =
c4 = 1:
c3 + S + 1 = O + 10
If c3 = 1, S + 1 = O + 10
Thus, S + 1 ≥ 10, and the only possible legal value for S is 9 and for
O is 0.
Similarly, if c3 = 1, S + 2 ≥ 10, and the only possible legal value for S is
8 and for O is 0.
Now the question is whether or not the order in which the two possible
values of c3 needs to be considered. In this case, the order does not matter
because the domain of S is reduced to only one legal value (i.e., 8 or 9) in
both cases (for both possible values of c3)—that is, 1 or 0, respectively. In
cases where testing a probable value for a variable results in a domain that
is too small or null for its neighboring variable, such a variable is considered
last. This heuristic, choosing the value that rules out the least possible values
for the neighboring variables, is called the least constraining value (LCV) [4].
Thus, when using the MRV heuristic, we can find the value of O and
can reduce the domain of S to two values: 8 and 9. This prevents us from
having to test all other values from the domain for the variables, which
would later fail anyway.
84 • Artificial Intelligence Problems and Their Solutions
After choosing the LCV* for a variable, we can start deriving possi-
ble legal values for the remaining variables and proceed further down the
search tree toward the solution. This technique is called forward checking.
Continuing this way, if we were to reach a dead end or a state where no
legal values are left for a variable, we trace back to the last assignment. This
technique is called backtracking.
Overall, each solution we found follows the same general concept: show
(at least) the completely encrypted and decrypted cryptarithm and give a
step-by-step description of how the solution was found.
When analyzing the solutions we found Table (10), we can see that they
are all represented using text. This is because a mathematical arithmetic
problem, along with any reasoning behind it, is easily understood by words
Difficulty
8/10
Complex.
O((n – (constrs + N/A))!)
Key
Int or Ext?: Intensional or Extensional—Is the solution intensional or extensional?
Intly/Extly: Intensionality/Extensionality—How intensional or extensional is the solution?
Rep.: Representation—How is the solution represented?
HW?: Human Window—Does the solution exist in the Human Window?
Corr?: Correctness—Is the solution correct?
Grn Sz: Grain Size—How much computation (large) or memory (small) does one need to solve the solution?
Exec: Executability—How executable is this solution?
Compr: Comprehensibility—How comprehensible is this solution?
Prob. Solv. Mthd: Problem-Solving Method—What method is used in the solution to solve the problem?
Flex: Flexibility—How flexible is this solution (i.e., can this solution be represented in other ways)?
Mode of Conv: Mode of Conveyance—In what ways can this solution be reproduced/replicated?
Opt?: Optimal—Is the solution optimal?
Solution:
c1 c2 c3 c4 c5
DONALD
GERALD
----------------
ROBERT
Steps:
1) T is even (D + D = an even number)
2) D 5 c5 = 1
D 4 c5 = 0
3) L 5 c4 = 1
L 4 c4 = 0
4) A 5 c3 = 1
A 4 c3 = 0
5) c5 = 1 R is odd
c5 = 0 R is even (L + L)
R is not 0 (R and L cannot both be 0)
6) c4 = 1 E is odd
c4 = 0 E is even (A + A = an even number)
E not 0 (E and A cannot both be 0)
7) c2 = 0 E=0
c2 = 1 E = 9 and c3 + N + R > 9
8) c1 + D + G 9 (no carryover)
R D
R G
...
...
...
...
...
Another feature that could be an issue with this solution is the fact that,
unlike the “Knowledge Table Solution,” the cryptarithm is not reiterated in
between steps. This further reduces the amount of guidance provided to the
reader and thus may further reduce the comprehensibility of the solution.
Cryptarithms • 89
Finally, you may notice that the solution begins by analyzing the letters
in the rightmost column as opposed to the leftmost column. As seen in the
previous solutions in this chapter, we usually begin by analyzing the let-
ters in the leftmost column and then moving toward the rightmost column.
This approach is more efficient because it is likely to determine the values
of the carryover variable earlier in the process. However, beginning from
the rightmost column may result in more steps, which is the case in the
“Donald Solution.” Therefore, this may also reduce the executability of the
solution.
Today, there are many apps available on iPhone and Android phones
that have kept the interest in cryptarithmetic alive. With the advent of
modern computers a few decades ago, people started publishing computer-
generated cryptarithms that were too complex to be solved by humans,
5.8 REFERENCES
6
THE RED DONKEY PUZZLE
6.1 BACKGROUND
6.2 SOLUTION
We now have space to move the vertical blocks so block 2 can move lat-
erally, as seen in Figure 39 after the 26th move. However, the small square
blocks need to be adjacent to block 2 to help it move because the vertical
blocks still restrict block 2’s movement. The small square blocks are adja-
cent to the donkey block in Step 31 (Figure 40).
By Step 41 (Figures 41 and 42), the horizontal block has moved to the
bottom right corner, allowing vertical blocks 4 and 1 to move further down,
making space for one of the two remaining unit square blocks to move up.
It is very important to have one of the single unit square blocks remain at
the bottom to avoid creating a unit square space, which can hinder move-
ment of the larger blocks. With the three small square blocks on top, verti-
cal blocks 4 and 1 can be moved to the left side so the donkey block can
move a row down, as shown in Step 48 (Figure 43). An observation of the
current state reveals that the donkey block is still constrained by the vertical
The Red Donkey Puzzle • 97
blocks on both sides, and it is necessary to move them to the top to enable
the donkey block to move freely farther down.
blocks 5, 9, and 10. The last step is achieved in the 81st move, when
the donkey block moves right to the center.
The initial and goal states are shown in Figures 50 and 51, respectively.
A careful observation of the goal state suggests that a significant milestone
while working backward is when the donkey block is moved to the left and
one row up, while the horizontal block moves to the bottom right. This is
the state represented in Step 71 in the previous solution.
The Red Donkey Puzzle • 99
Moving back to the initial state, we can consider the state in Figure 52
as our intermediate goal state and work toward it. Thus, our new subgoal
in our forward search is to move the donkey block and the horizontal
block two rows below their current positions. The second of the two sub-
goals, if achieved optimally, can be done in 21 steps, as shown in 52.
Thus, the search technique of mean-ends analysis can be used to reduce
the difference between the current state and the goal state [4, 5]. Kose
(2012) solved the Klotski puzzle using the bidirectional search in 116
moves [6].
■ Moving the small square blocks to the top to help move the vertical
blocks out of the donkey block’s pathway to the center
■ Moving all the vertical blocks to the top once the donkey block is in
the center
Difficulty
9/10
Complex
O(bd/2)
Key
Int or Ext?: Intensional or Extensional—Is the solution intensional or extensional?
Intly/Extly: Intensionality/Extensionality—How intensional or extensional is the solution?
Rep.: Representation—How is the solution represented?
HW?: Human Window—Does the solution exist in the Human Window?
Corr?: Correctness—Is the solution correct?
Grn Sz: Grain Size—How much computation (large) or memory (small) does one need to solve the solution?
Exec: Executability—How executable is this solution?
Compr: Comprehensibility—How comprehensible is this solution?
Prob. Solv. Mthd: Problem-Solving Method—What method is used in the solution to solve the problem?
Flex: Flexibility—How flexible is this solution (i.e., can this solution be represented in other ways)?
Mode of Conv: Mode of Conveyance—In what ways can this solution be reproduced/replicated?
Opt?: Optimal—Is the solution optimal?
TABLE 11 Ranking The Red Donkey Puzzle Solutions According to the Human Window.
especially to the donkey piece, which has an actual image of a donkey on it.
Additionally, above each image in the solution is a number that represents
its corresponding step number. Finally, the quality that greatly increases the
overall comprehensibility is the inclusion of the arrows. The arrows indicate
which tile was moved from the previous state to get to the current state and
in how many units it moved. This prevents the need to compare pictures for
two consecutive steps to determine which tile has been moved. The picture
of the current step can simply be viewed, and the arrangement of the previ-
ous step can be determined by it.
102 • Artificial Intelligence Problems and Their Solutions
Initial State
Subgoal 3: Move one 1" × 1" tile to the bottom and the donkey two rows down.
Subgoal 3: Move one 1" × 1" tile to the bottom and the donkey two rows down.
Goal
FIGURE 54 The “Hollow Solution” (Shortened).
in 116 steps, just like the breadth-first search [6]. However, this search is
more sophisticated because it greatly reduces the number of nodes needed
to be visited and expanded. This is because both ends of the search start
with a parent node and meet each other at a common middle step (see
Section 6.2).
Since solutions are found efficiently through the use of search algo-
rithms, the complexity of The Red Donkey Puzzle can be evaluated in
terms of a search tree. In the worst case, the runtime and space needed for
the breadth-first search is O(bd), where b is the branching factor and d is
the depth of the tree. For the bidirectional search, however, the runtime
and space needed is O(bd/2) [6]. This shows that the bidirectional search is
more efficient than the breadth-first search, even though they find the solu-
tion in the same number of steps.
Many playable programs for The Red Donkey Puzzle are available
online, where you can play the puzzle, become familiar with the problem,
and learn to differentiate between good and bad moves.
It would be extremely difficult to memorize all the movements, so you
would have to draw all the moves on a piece of paper. However, drawing
the search tree can be difficult and tedious and would require a lot of space.
This is why being able to solve the puzzle on a computer is preferable.
Physical puzzles, such as those made of cardboard or wooden blocks, and
virtual puzzles, such as games on a computer or a smart phone, are only
some examples. These are the most extensional forms of representation of
the problem, as the problem solver can physically or virtually manipulate
the problem states. An online game can be found at http://www.bsswebsite.
me.uk/Puzzlewebsite/Reddonkeypuzzle/Reddonkeypuzzle.htm.
6.7 REFERENCES
7
THE 15 PUZZLE
7.1 BACKGROUND
to 34. In 1879, a new and improved version of The 15 Puzzle spread through-
out the United States after Chapman’s son introduced the puzzle [1]. Even-
tually, the puzzle was popular all over the United States, and by 1880, it
had spurred a puzzle craze. The puzzle eventually made its way to Canada
and then to Europe. By July 1880, however, its popularity had begun to
wane [2].
At one point Chapman unsuccessfully attempted to patent the puzzle.
This is most likely because it was too similar to Ernest Kinsey’s “Puzzle-
Blocks” which was patented in 1878 [1].
The invention of The 15 Puzzle is often incorrectly accredited to
American chess player, chess composer, and recreational mathematician
Samuel Lloyd. Until his death, Lloyd insisted that he had invented the
puzzle in 1891, and at one point, he revived its popularity when he intro-
duced The 14-15 Puzzle, which was very similar, except two of the tiles
were switched (see Section 7.2). However, despite these claims, it was in
fact Chapman who invented The 15 Puzzle [1].
The 15 Puzzle consists of 15 square tiles numbered 1 to 15, bounded in
a closed 4” × 4” area. The 15 tiles fill up 15 of the spaces in the area, while
the 16th space is left empty so each tile has limited space to move. The goal
is to reposition the squares so they are placed in numerical order by row.
Unlike the problems we have analyzed so far, The 15 Puzzle does not
have a specific predefined initial setup. Therefore, any arrangement of the
tiles, including the goal arrangement, can be considered an initial state.
There are 16! * (2.09 × 1013) arrangements in which the tiles can be
placed. However, according to a study by Woosly Johnson and William Story,
there are only 16!/2 possible positions in which the goal setup can actually
be achieved. In 1879, Johnson and Story researched The 15 Puzzle and
discovered that all puzzles with arrangements of even parity are solvable,
whereas those of odd parity are not [3]. That is, if the number of tile inter-
changes (or permutations) needed to transform a particular arrangement
into a solvable arrangement is even, then that particular arrangement itself
is solvable. If it is odd, it is unsolvable. More than a decade after this dis-
covery, Sam Lloyd presented his variation of the problem to the public
The 15 Puzzle • 111
that involved solving his version of the 15 Puzzle whereby titles numbered
14 and 15. The 14-15 Puzzle consists of one interchange, is of odd parity,
and therefore is unsolvable [4].
Although the number of possible positions is lower than expected, 16!/2
(1.05 × 1013) possible initial tile arrangements is still a very large problem!
However, finding the solution to The 15 Puzzle can be very straightforward.
The most valuable problem-solving technique to use is solving subgoals.
The subgoal is to achieve a completed row, and once that is accomplished,
one can go on to the next step. However, as you will see (in Section 7.3),
there are special situations, such as solving the fourth row, in which the
completed third row must be uprooted.
Generally speaking, The 15 Puzzle is a type of n puzzle, with the value
n representing an integer greater than 1. The rules and goal of any n puzzle
are the same as The 15 Puzzle. The only difference is that it consists of n
square tiles numbered from 1 to n placed in a closed sqrt(n +1) × sqrt(n + 1)
area, with the nth location left as an empty tile space. However, no matter
how big the problem, the same problem-solving technique can be used. It
may just take more moves to complete. In this book, we perform our analy-
sis solely on The 15 Puzzle.
7.3 SOLUTION
The first step is to move the 1 tile to the upper left corner of the board.
This is a relatively simple step to achieve. Since the other tiles have not
been properly positioned, it does not matter how they are moved as long
112 • Artificial Intelligence Problems and Their Solutions
as the 1 tile is placed in its correct position. Let’s say the puzzle is arranged
like in Figure 56.
The black square represents the empty tile space, and the gray squares
represent tiles that we will not consider at this point.
First, arrange the tiles so the empty space is near the 1 tile (Figure 57).
Now, move the 1 tile to the upper left corner (Figure 58).
The 15 Puzzle • 113
Basically, the general idea behind moving a target tile is to move all
temporarily disregarded tiles around it until the empty space is in the gen-
eral direction of the correct position relative to the target tile. Then use that
empty space to move the target tile toward its goal position. Continue this
until the target tile is in the correct position.
Figure 58 shows the general idea behind moving a tile throughout
the board. From now on, future diagrams will only show moves that are
114 • Artificial Intelligence Problems and Their Solutions
Now we position the 2 tile to the right of the 4 tile. Although the 4 and
2 tile positions are very close to each other, the 4 tile does not need to be
disturbed from its correct position in order to position the 2 tile next to it.
This can be done by moving the 2 tile and the empty spot to any position
in the center “square” located in between the 1 and 4 tiles. For example, a
sufficient tile arrangement would be as shown in Figure 60.
At this point, you have probably noticed that we have not placed the
2 tile in its correct position. However, temporarily placing it here will allow
us to easily position the 3 tile.
Now, arrange the 3 tile and empty slot so they are in the positions shown
in Figure 62.
After positioning the 2 tile, the first row might look like Figure 64.
Now rotate the tiles in the “square” so they are arranged as in Figure 66.
The next goal is to solve the second row. To do so, follow the same tech-
niques that were used to solve the first row. Move the 5 tile to the upper
left, the 8 tile to the upper right, the 6 tile to the left of the 8 tile, and use
the same techniques that were used to solve the 3 tile to solve the 7 tile
(Section 7.31 and Section 7.3.2). If done correctly the puzzle should look
like Figure 68.
At this point, the tiles in the second row do not need to be repositioned
again. We are now halfway done, leaving us with two more rows to solve. As
you can see, the amount of space is being reduced, and there is less room to
move tiles. Positioning the last seven tiles will be a little trickier.
Moving on, the next goal is to solve the third row. First, move the 9 tile
to the leftmost position, and then move the 12 tile to the rightmost position,
as in Figure 69.
If this were the case, simply rotating the tiles in the “square” twice
would complete the third row. However, this will certainly not always be
the case. For example, you may have a position like the one in Figure 71.
Notice how we have the empty space below the 9 tile. This would be
acceptable if one of the temporarily disregarded tiles was to the right of it,
but unfortunately that is not the case. With this arrangement, it would be
impossible to solve the puzzle without moving the 9 tile. Follow the steps
in Figure 72.
Now, rotate the tiles in the center square so one of the temporarily
disregarded tiles is next to the 9 tile and the empty slot is above it, as shown
in Figure 73.
The 15 Puzzle • 121
We have only one row to deal with. At this point, the puzzle is either
solved or positioned incorrectly, as in Figure 76.
Let us assume the tiles in the last row are positioned incorrectly. Until
this point, we have followed a basic strategy that prevented the need to
displace any tiles that belong to a completed row. To proceed in finding the
solution, that rule must be broken. To deal with this arrangement, we begin
by once again using the corner technique. First move the 9 and 10 tiles so
they are aligned vertically to each other. This involves moving the 9 tile into
the last row and moving the 10 tile into the position where the 9 tile should
be (Figure 77).
The 15 Puzzle • 123
At this point, the tiles in the center “square” should only be those that
belong to the final row (i.e., 13, 14, and 15). Arrange them as in Figure 79.
Like The Red Donkey Puzzle, we have not found many solutions for
our Human Window analysis of The 15 Puzzle. Additionally, the majority
of them are identical to the solution discussed in Section 7.3 and to one
another. Therefore, they each use similar problem-solving methods and
representations. Each solution demonstrates a general method in which
descriptions are used, along with visual images as guidance, to solve The 15
Puzzle regardless of its initial arrangement. Therefore, the solutions can be
considered intensional because of this generality. However, they are ranked
relatively low on their intensionality because they are partially extensional
(i.e., diagrams).
The 15 Puzzle • 125
Difficulty
4/10
Complex
O(bd/2)
Name Int or Intly/ Rep. HW? Corr? Grn Sz Exec Compr Prob. Solv. Flex Mode of Opt? Total
Ext? Extly Mthd Conv
Txt Editor;
Descr. Y w/
In-Place Int. 3/10 Y Small 5/10 7/10 Sub-goals 7/10 Img Maker; N 22/40
w/ Vis. Cycles
Hand
Txt Editor;
Descr. Vis. Repr;
Jurgen Int. 4/10 Y Y Ideal 4/10 6/10 8/10 Img Maker; N 22/40
w/ Vis. Sub-goals
Hand
Txt Editor;
Optimal Ext. 3/10 Text Y Y Ideal 9/10 5/10 Vis. Repr. 9/10 Y 26/40
Hand
Txt Editor;
Descr. Vis. Repr;
Real Int. 9/10 Y Y Ideal 9/10 7/10 7/10 Img Maker; N 32/40
w/ Vis. Sub-goals
Hand
Txt Editor;
Descr. Vis. Repr;
Tile Int. 5/10 Y Y Ideal 10/10 9/10 7/10 Img Maker; N 33/40
w/ Vis. Sub-goals
Hand
Descr. Vis. Repr; Txt Editor;
W-how Int. 5/10 Y Y Ideal 6/10 8/10 7/10 N 26/40
w/ Vis. Sub-goals Img Maker
Key
Int or Ext?: Intensional or Extensional—Is the solution intensional or extensional?
Intly/Extly: Intensionality/Extensionality—How intensional or extensional is the solution?
Rep.: Representation—How is the solution represented?
HW?: Human Window—Does the solution exist in the Human Window?
Corr?: Correctness—Is the solution correct?
Grn Sz: Grain Size—How much computation (large) or memory (small) does one need to solve the solution?
Exec: Executability—How executable is this solution?
Compr: Comprehensibility—How comprehensible is this solution?
Prob. Solv. Mthd: Problem-Solving Method—What method is used in the solution to solve the problem?
Flex: Flexibility—How flexible is this solution (i.e., can this solution be represented in other ways)?
Mode of Conv: Mode of Conveyance—In what ways can this solution be reproduced/replicated?
Opt?: Optimal—Is the solution optimal?
The solution considered the MHWC is the “Tile Solution,” which is the
same as the one in Section 7.3. It provides a step-by-step method on how
to solve The 15 Puzzle with any initial arrangement. At each step, a simple
description is given on what tiles to move and how to do it. Provided at
each step is a picture of the puzzle itself, which contain tiles that are either
shaded or numbered. The tiles that are shaded are unimportant at a par-
ticular step and can be ignored, while the numbered tiles are important or
have been correctly placed. These images are used to show what the puzzle
would look like after the execution of each step. Finally, arrows are used to
show how certain tiles were moved at a step. These brief, but to the point,
directions, along with the images, make the solution very comprehensible
and executable.
To improve this solution even further, actual images of the puzzle
can be used instead of a grid or a table. This will make the solution even
more extensional. A solution that uses this approach is the “Real-Puzzle
Solution” [6].
The solution assessed as the LHWC is the “Optimal Solution” (Figure 81).
A representation similar to this was developed by B. MacKenzie [7]. It is
referred to as such because it demonstrates how to solve The 15 Puzzle in
the least number of possible steps. Optimal solutions may be feasible for
machines by clever or precise algorithms, but for people, finding optimal
solutions to nontrivial problems is usually very difficult, if not impossible.
Finding an optimal solution to The 15 Puzzle depends on the initial
arrangement of the tiles. Of all 16!/2 possible initial tile arrangements, only
The 15 Puzzle • 127
The Solution
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 X
X = vacant position (empty tile space)
Moves (direction of X):
1. L1 11. R1 21. R3 31. R2 41. R2
2. U1 12. U1 22. D1 32. U1 42. D2
3. R1 13. R2 23. L3 33. R1 43. R1
4. U2 14. U1 24. D1 34. D2
5. L3 15. L3 25. R2 35. L3
6. D3 16. D1 26. U2 36. U1
7. R2 17. R3 27. L1 37. R3
8. U2 18. U1 28. D3 38. D2
9. L2 19. L3 29. L1 39. L3
10. D2 20. U1 30. U2 40. U2
Key
L = left
R = right
U = up
D = down
7.7 REFERENCES
1. Slocum J., and Sonneveld, D. (2006). The 15 Puzzle. Beverly Hills, CA:
Slocum Puzzle Foundation
2. Slocum, J., and Weisstein, E.W. (2013)15 Puzzle. Available at http://mathworld.
wolfram.com/15Puzzle.html. Accessed on January 9, 2014.
3. Johnson, W.W., and Story, W.E. (1879). “Notes on the ‘15’ Puzzle.” American
Journal of Mathematics 2 (4): 397–404.
4. Grant, H. (2002). The Fifteen Puzzle. Available at http://www.math.ubc.
ca/~cass/courses/m308-02b/projects/grant/fifteen.html. Accessed on January 9,
2014.
5. Yates, J. (2013). Fifteen Puzzle Solution: How to Solve the Famous 15 Puzzle.
Available at http://www.chessandpoker.com/fifteen-puzzle-solution.html.
Accessed on January 9, 2014.
6. Schmidt, W. (2013). Wayne Schmidt’s 15-Puzzle Solving Page. Available at
http://www.waynesthisandthat.com/15puzzle.htm. Accessed on January 9,
2014.
7. Norskog, B. (2013). The Fifteen Puzzle Can Be Solved in 43 ‘Moves.’”
Available at http://cubezzz.dyndns.org/drupal/?q=node/view/223. Accessed on
January 9, 2014.
8. Chiang, K-Y. (2013). Finding Optimal Solution of 15 Puzzle. Available at
http://www.cs.utexas.edu/~kychiang/files/Finding_Optimal_Solution_of_15_
puzzle.ppt. Accessed on January 9, 2014.
The 15 Puzzle • 131
9. Lucci, S., and Kopec, D. (2013). Artificial Intelligence in the 21st Century.
Dulles, Virginia: Mercury Learning Inc.
10. Ratner, D., and Warmuth, M.K. (1986). Finding a Shortest Solution for the
N × N Extension of the 15-PUZZLE Is Intractable. National Conference on
Artificial Intelligence. Santa Cruz, CA: University of California Santa Cruz.
CHAPTER
8
THE KNIGHT’S TOUR PROBLEM
8.1 BACKGROUND
efficient method is solving subgoals, and it is also the most commonly used
technique. The solutions we have found use some of the more popular sub-
goal methods.
One method is a relatively straightforward method discovered by
Abraham de Moivre. When starting at a corner square, the knight will first
visit all of the squares around the edges of the board and then visit all of the
remaining squares in the center. The heuristic is that at every choice point,
the knight visits the square closest to the edge (i.e., the square with the
smallest in-degree) first. A similar method is used in the solution presented
in this chapter (see Section 8.3).
A second popular method is square and diamonds. This solution essen-
tially divides the chessboard into four 4” × 4” subboards. In each of these
subboards, four patterns are formed with the knight during the tour: a
rhombus, a square, and a mirror image for each. This method is used in the
“D&S Solution” [4].
A third method is tessellation. The basis of this method is to move the
knight in a path that would trace the shapes of four polygons that, when
combined together, form a tessellation. A tessellation is a group of shapes
that can fit perfectly with one another on a plane without overlapping. With
this method, the knight can start at any square on the board and form the
polygon that the square is a part of. After completing that shape, the knight
can simply move to another square that is a part of one of the other three
polygons and travel along a path to trace its shape. The tour is complete
after the knight traces the shapes of the four polygons. If done correctly,
the tessellation method can create a closed tour. This method is used in the
“Tessellation Solution,” which was developed by Daniel E. Thomasson [5].
8.3 SOLUTION
This section presents a relatively simple solution, with steps and rules
that are easy to follow and remember. It is based on the method developed
by Abraham de Moivre, in which the knight travels on the outer edges of
the chessboard. Using this method, we can still achieve a closed tour. How-
ever, there are specific points in the solution where the heuristic must be
broken. This approach is similar to one developed by Andrew Joseph, a
former student of Dr. Kopec’s.
136 • Artificial Intelligence Problems and Their Solutions
A closed knight’s tour can be achieved by making the knight follow two
general rules:
Rule 1: Stick as close to the outer edges of the board as possible.
Rule 2: When the opportunity presents itself, corner squares must be
taken.
For this solution, our knight starts at the lower left corner of the board
(Figure 83).
The first general idea is to go in a spiral motion around the board, which
is something the knight will be doing for most of the solution. We will start
by traversing the outer squares of the board in a clockwise motion (Figures
84 and 85).
At this point, we have the opportunity to move into the upper right-
hand corner of the chessboard. We will use this opportunity and have the
knight move there (Figure 86).
The Knight’s Tour Problem • 137
Although this set of moves does not help the knight visit the lower
right corner of the board, visiting squares 12 to 14 will help the knight with
future moves. For this “favored” solution, we recommend that the problem
solver simply memorize this exception, as it will be necessary when we make
a similar maneuver at square 36. Until then, continue to follow the rules
(Figures 89 to 92).
We now have the opportunity to fill the final corner on the upper left of
the board. We will take advantage of it (Figure 96).
Now that we have reached square 36, we will once again break the
rules. Move the knight to the squares shown in Figure 98.
At this point, continue to follow the rules, with the knight once again
traversing the outer squares of the board clockwise, as shown in Figures 99
to 102.
FIGURE 101 Visiting Squares 45–47. FIGURE 102 Visiting Squares 48–50.
The Knight’s Tour Problem • 141
FIGURE 103 Visiting Center Squares 51–54. FIGURE 104 Visiting Center Squares 55–58.
Difficulty
5/10
Complex
O(n)
Prob.
Int or Intly/ Mode of
Name Rep. HW? Corr? Grn Sz Exec Compr Solv. Flex Opt? Tot
Ext? Extly Conv
Mthd
Y w/ Bcktrck
Algorithm Int. 8/10 Code Y Ideal 8/10 7/10 7/10 Txt Editor N 30/40
cycles w/ Heurist
Txt
Vis. Repr.
D&S Int. 6/10 Y Y Ideal 9/10 6/10 Subgoals 7/10 Editor; Y 28/40
w/ Descr.
Img Mkr
Grid/Table; Vis. Repr.; Img/Tbl
Green Ext. 8/10 Y Y Ideal 5/10 7/10 8/10 Y 28/40
Img Subgoals Mkr
Grid/Table; Vis. Repr.; Img/Tbl
Narayan Ext. 7/10 Y Y Ideal 8/10 7/10 7/10 Y 29/40
Img Subgoals Mkr
Grid/Table; Vis. Repr.; Img/Tbl
Semi-Magic Ext. 7/10 Y Y Ideal 4/10 7/10 7/10 Y 25/40
Img Subgoals Mkr
Grid/Table; Vis. Repr.; Img/Tbl
Simple Ext. 8/10 Y Y Ideal 8/10 9/10 8/10 Y 33/40
Img Subgoals Mkr
Grid/Table; Vis. Repr.; Img/Tbl
Tessellation Ext. 8/10 Y Y Small 10/10 7/10 8/10 Y 33/40
Img Subgoals Mkr
Grid/Table; Vis. Repr.; Img/Tbl
Wiki Ext. 7/10 Y Y Ideal 8/10 7/10 8/10 Y 30/40
Img Subgoals Mkr
Key
Int or Ext?: Intensional or Extensional—Is the solution intensional or extensional?
Intly/Extly: Intensionality/Extensionality—How intensional or extensional is the solution?
Rep.: Representation—How is the solution represented?
HW?: Human Window—Does the solution exist in the Human Window?
Corr?: Correctness—Is the solution correct?
Grn Sz: Grain Size—How much computation (large) or memory (small) does one need to solve the solution?
Exec: Executability—How executable is this solution?
Compr: Comprehensibility—How comprehensible is this solution?
Prob. Solv. Mthd: Problem-Solving Method—What method is used in the solution to solve the problem?
Flex: Flexibility—How flexible is this solution (i.e., can this solution be represented in other ways)?
Mode of Conv: Mode of Conveyance—In what ways can this solution be reproduced/replicated?
Opt?: Optimal—Is the solution optimal?
TABLE 13 Ranking The Knight’s Tour Problem Solutions According to the Human Window.
144 • Artificial Intelligence Problems and Their Solutions
shows the entire path the knight took, as well as numbers on each square that
indicate the sequence of the moves the knight made in completing the tour.
Although the solution is comprehensible, it is possible that the repre-
sentation can be improved to increase its overall comprehensibility. For
example, another attribute that could be added are letters and numbers to
indicate the names of rows and columns, respectively, akin to those of an
actual chessboard. This can make the solution more traceable, and specific
sequences and squares can be traced, memorized, or just identified.
What makes this solution the MHWC is the method used. Not only is
the method highly executable, but it requires little to no memory to carry
out, which is ideal for most human beings. Although there are a few rules to
follow and some locations in which the heuristic must be broken, they are
relatively easy to remember.
You may notice from Table 13. that the “Tessellation Solution,” devel-
oped by Daniel E. Thomasson (see Section 8.2), has higher executability
than the “Simple Solution.” This is because the tessellation method not only
produces a closed tour, but it also guarantees that a tour will be produced
after moving the knight around the board so it traces the four polygons. No
matter where the knight starts on the board, if those four shapes are traced,
a tour will be created. Thus, the executability of the solution is very high.
Unfortunately, to carry out this method, a decent amount of memory is
required, as one would have to memorize each of the four shapes and which
squares correspond to those shapes. Therefore, the grain size of the solu-
tion is considered small. The “Simple Solution,” however, provides steps
that are easy to remember.
known as the magic constant [7]. If the values of each row and column add
up to this number, but the diagonals do not, it is considered a semi-magic
square.
Finding a knight’s tour can be thought of as producing an 8” × 8” square
whose values range from 1 to 82. Each square in the chessboard can be
assigned a value corresponding to the step number in which the knight
landed on that square. After the tour is completed, if the values of the
squares in each row, column, and diagonal add up to the same number,
the entire chessboard is considered a magic square. It has been proven,
however, that a magic square cannot be formed by a knight’s tour on an
8” × 8” board. However, it is possible to find a tour that results in a semi-
magic square [7]. The first original semi-magic square was discovered by
Leonhard Euler, where each row and column of the chessboard added up
to the magic constant of 260 [2].
The “Semi-Magic Solution” shows a method of how a semi-magic
square is formed with the same magic constant of 260. Using the squares
and diamonds method, two simultaneous knight’s tours are produced: one
that starts at square 1 and increases by step, and another decreasing by step.
Both tours always visit squares vertical to one other, of which the step num-
bers add up to 49 and 81. Although this solution produces both a completed
knight’s tour and a semi-magic tour and reveals the symmetry behind it, we
will analyze the representation of it in terms of the Human Window, as if it
were intended to be shown to any audience (i.e., those unfamiliar with The
Knight’s Tour Problem). The solution is also shortened to save space, as it
contains a total of 32 steps.
This solution may not be very executable for humans because there
are too many goals to remember. The simultaneous squares and dia-
monds method is repeated for all four quadrants, and the values of the
columns add up to 98. Afterward, the same process is continued, except the
steps must be numbered to add up to 81. To carry out this solution, a person
must remember exactly which shapes to produce at any given step and must
remember the order in which they are formed.
The solution may also not be very comprehensible either. This solution
does not have a knight to follow in the tour, nor is there a line indicating
the path. It simply shows the numbers of the squares the knight would land
on during a particular step. This may make the solution hard to follow and
could take a person away from the fact that this is a solution to The Knight’s
The Knight’s Tour Problem • 147
Tour Problem. Finally, the squares are shaded differently to indicate the
particular shapes (i.e., diamonds and squares) being formed. The mixture
can make the solution hard to comprehend, even for the image that shows
the completed knight’s tour.
8.8 REFERENCES
9
MASTERMIND
A A A A A
B A B D B
E B C C E
F B C D E
9.1 BACKGROUND
code chosen by another other player, known as the code-maker. This code
is a sequence of four pegs that can be any of six different colors, with same-
colored pegs allowed in the same sequence. The code-breaker must break
this code by determining the exact colors and order of these pegs. To do
so, the code-breaker must make a series of at most 10 guesses. After each
guess, the code-maker gives the code-breaker a score in the form of two
values: the number of pegs that are the right color and in the correct posi-
tion and the number of pegs that are the correct color but not in the correct
position. These numbers are represented by small black and white pegs,
respectively. If in 10 guesses the code-breaker cannot determine the cor-
rect sequence, the code-maker wins. [2]
Since its release in 1972, there have been a wide variety of alternate
versions of the original game. One version is called Mastermind44, which
includes six colors, five pegs to a sequence, and as many as three code-
makers [3]. Another version is Ultimate Mastermind, which includes eight
colors and five pegs to a sequence [4].
Like The 15 Puzzle, Mastermind does not have a specified initial state.
However, unlike any of the problems we have analyzed in this book, this
problem does not have a specified goal state. Additionally, for the other
problems, we attempt to find methods of achieving the goal, while in Mas-
termind we try to find the goal itself. We could say that The Knight’s Tour
Problem is similar in that there is no specific set goal. However, we do know
that the knight must visit all 64 squares, so it is not the same.
In the original Mastermind game, there are a total of 6 × 6 × 6 × 6
= 1,296 possible combinations, and the code-breaker must determine the
one correct sequence of colors [5]! With only 10 guesses available, the key
is to reduce the number of possible combinations as much as possible with
each guess. This can be done by analyzing the score given at each guess and
using deduction to determine which colored pegs to use and which not to
use, and in which order they must be placed. Therefore, deduction is the
most valuable problem-solving technique to use in solving for the correct
sequence of pegs and winning Mastermind. This kind of logical deduction
Mastermind • 153
is also performed for the solution to the n coins problems to determine how
to best split the number of coins for each weighing.
9.3 SOLUTION
• ABBC (2, 1)
1. The first guess should always be the sequence AABB. This is not only the
simplest guess, but it is also very important because, even in the worst
154 • Artificial Intelligence Problems and Their Solutions
case, this guess greatly reduces the number of possibilities remaining (in
the worst case, it reduces the 1,296 possible guesses to 256). [5]
2. You must use the score of the first guess to make assumption(s) as to
which of the pegs from the previous guess (i.e., pegs A and B) should
be used for the next guess. For example, if the score is a total of 0, pegs
A and B should not be used again for this game. If the score is a total
of 1 or 2, use both an A and a B in the next guess to determine which A
or B is in the sequence. If the score totals 3, use two A pegs and one B
peg in the next guess. Finally, if the score happens to be 4, that means
all four pegs are in the sequence and must simply be arranged to the
correct order.
3. Repeat Step 2 for future guesses until all the peg colors have been
used (that is, if we do not wind up having a score of 4 before then). At
this point there should be enough information from all the guesses
already made to use deduction and solve for the sequence.
At first, the above steps may seem too broad and unclear. However, we
will be providing five examples so you can understand them better.
9.3.1 Example 1
Let’s start with an easy example. The goal sequence is CEDF. We start
with the required first guess and get Figure 110.
1 AABB (0, 0)
1 CCDD (2, 0)
2 AABB (0, 0)
We now have a score of 2. Even better, we have two pegs that are in
their correct positions. However, because we don’t know which pegs are
correct, we need to make an assumption. We can pick any two, but it is best
to have both colors included in the next guess. We will keep the first C and
first D in the sequence, and, since there are two spots available, we will add
two E pegs (Figure 112).
Assumption
2 CCDD (2, 0)
1 AABB (0, 0)
Our score has increased to 3, with all three pegs in the correct posi-
tion. From this, we can conclude three things: our assumptions about the
inclusion and location of the C and D pegs were correct; peg E is in the
sequence; and with one peg still incorrect and one color remaining, peg F
must also be in the sequence. This means that one of the E pegs must be
removed. We will make the assumption that the E in position 2 is correct
and the E in position 4 should be replaced with an F (Figure 113).
Assumption
3 CEDE (3, 0)
2 CCDD (2, 0)
1 AABB (0, 0)
Thus, we have solved for the sequence. Of course, guess 4 was a lucky
guess. If we had assumed the E in position 4 was correct instead of position
2, we would have Figure 114.
Assumption
9.3.2 Example 2
1 AABB (1, 1)
We see that we have a score of 2, with one peg in the correct position
and one in the wrong position. Having a score of 2 for the first guess makes
it hard to determine which A or B is correct. Let’s make the assumption
that both colors are in the final sequence, and we will put both in the next
guess. Let’s assume the first A peg is the correct spot and that one of the B
pegs is out of place. Move the B to position 2 and add two of the next color
to the sequence (Figure 116).
Mastermind • 157
Assumption
1 AABB (1, 1)
We now have our score reduced to 1, with one peg being out of place.
This gives us two conclusions: C is not in the final sequence, and either two
A pegs or two B pegs are in the final solution, but not both. We know this
because our score of 2 in the first guess has been reduced to 1. For guess
3, we will assume that two As are in the sequence. Now we will make some
more assumptions based around this assumption. Since our current score
indicates that we have one peg out of place, we know that A cannot be in
position 1. Additionally, from looking at our score in guess 1, one of the
A pegs must be in position 2, since there was a black peg. Therefore, let’s
assume that one A is in position 2. The second A can be placed in either
position 3 or 4, so let’s will assume it is in 3. Finally, we will now introduce
peg color D (Figure 117).
Assumption
2 ABCC (0, 1)
1 AABB (1, 1)
We once again have a score of 2, with one peg in place and one out of
place. Unfortunately, with this guess, we cannot make any immediate con-
clusions. This guess can mean one of two things:
158 • Artificial Intelligence Problems and Their Solutions
1. Both As are in the sequence, and the Ds do not belong. We would just
need to move the A that is in position 3 to position 4.
2. The Ds are in the sequence, and our assumption about including the
As was wrong, leaving the two Bs as a part of the final sequence.
Let’s go with #1 and continue to assume that A is the correct color.
From looking at our score, we can assume that the A in position 2 is in place
because we have a black peg. We can also assume that A is in position 4, as
mentioned before. Finally, the other two positions will be replaced by an E
peg (Figure 118).
Assumption
3 DAAD (1, 1)
2 ABCC (0, 1)
1 AABB (1, 1)
This guess was very helpful. We have now come to three conclusions:
Assumption
4 EADA (3, 0)
3 DAAD (1, 1)
2 ABCC (0, 1)
1 AABB (1, 1)
9.3.3 Example 3
1 AABB (2, 0)
Assumption
1 AABB (2, 0)
With this guess, we have increased our score to 3 with the addition of a
white peg. Due to this increase from the last guess, we can make an obvious
conclusion that at least one C peg is in the sequence. We can also use some
logic to determine less obvious conclusions.
Let’s say we keep our assumption that A and B are in the correct posi-
tion. By this, we would have to say that there is one C peg in the sequence
and it represents the white peg. However, this does not make sense. Think-
ing that switching the two Cs would get one in the correct position is unre-
alistic. In other words, switching the two Cs cannot suddenly produce a
black peg, because nothing will change. With this single logical inference,
we can come to four conclusions:
1. There is only one C in the sequence.
2. C represents the black peg and is in the correct position.
3. Based on #1 and #2 and the score for this guess, A and B are in the
sequence.
4. One A or B is represented by the black peg, and the other is repre-
sented by the white peg. That is, one is in the correct position, and the
other is in an incorrect position.
First, let’s assume that the C peg belongs in position 2. We know that
A and B exist in the sequence, and now we must determine where to place
the A and B pegs. By analyzing the score from guess 1, in which there are
two black pegs, we can assume that the A peg can only be in either position
1 or 2, and B can only be in either position 3 or 4. Based on conclusion #4,
one A or B will remain in place, while the other will be moved to its next
possible position. For our next guess, let’s assume that A is represented by
the black peg and is in place and that B is represented by the white peg and
should be moved to its next possible position 4. Finally, position 3 will be
given the D peg, as shown in Figure 122.
Assumption
2 ACBC (2, 1)
1 AABB (2, 0)
Assumption
3 ACDB (0, 3)
2 ACBC (2, 1)
1 AABB (2, 0)
9.3.4 Example 4
The goal sequence is FBFF. For our last example, we have a goal that
is a little unusual, since we are now dealing with three of the same kind of
peg.
162 • Artificial Intelligence Problems and Their Solutions
1 AABB (0, 1)
We start a score of 1, with one peg out of place. We will assume that A
is in the sequence and is out of place. We will first assume it is in position 3.
The other three remaining positions will be filled with C pegs (Figure 125).
Assumption
1 AABB (0, 1)
With this guess we can make two conclusions: the A peg is not in the
sequence, so the B peg must be, and C is not in the sequence.
Remembering that guess 1 had a score of 1 with a white peg, the B peg
can only be in either position 1 or 2. We will first assume that peg B is in
position 1. The other positions will be given D pegs (Figure 126).
Assumption
3 BDDD (0, 1) B_ _ _
2 CCAC (0, 0)
1 AABB (0, 1)
For the next guess, we will place the B peg in position 2. The rest will
be given the E peg (Figure 127).
Assumption
3 BDDD (0, 1)
2 CCAC (0, 0)
1 AABB (0, 1)
We now have a black peg, which means our conclusion was correct and
the B peg was in fact located in position 2. Additionally, we can also make
two more conclusions: the E pegs are not in the sequence, and the remain-
ing positions are F pegs, since it is the last type of peg available (Figure 128).
Assumption
4 EBEE (1, 0)
3 BDDD (0, 1)
2 CCAC (0, 0)
1 AABB (0, 1)
This may be because, as mentioned before, this problem does not have a
specific goal, so only general tips and strategies can be used to help find
the goal. This, however, gives us an opportunity to use our Human Window
analysis from other problems in the book to determine what kind of solu-
tion can be considered the MHWC for Mastermind.
Since the Mastermind problem does not have one specific goal to
achieve, it is best to use a general, intensional solution, because this will
help find the end goal to a Mastermind game regardless of what it is. Like
the “Tile Solution,” combined with examples like those in Section 9.3, a
similar approach can be taken with a general solution to Mastermind. This
solution can contain one or more examples that demonstrate a step-by-
step method for solving for a particular goal sequence. Furthermore, there
should be enough examples so that every scenario that can possibly occur
can be explained. This will give the solution a high ranking of executability.
Additionally, to increase the comprehensibility of the solution, images of
the actual Mastermind game could be used at every step to give an idea of
what the game should look like.
The best solution to the Mastermind game for a machine so far is known
as the Five-Guess Algorithm, which was developed and presented in 1977
in a paper titled “The Computer as Mastermind,” by Donald Knuth. Knuth
based his algorithm on a study he did on the original Mastermind game. It
is called the Five-Guess Algorithm because it guarantees that any solution
can be found in five or fewer guesses [6].
The algorithm is quite sophisticated and intricate. Here is a brief
explanation:
3. For each of the 1,296 possible guesses, calculate how many possibili-
ties from P would be eliminated for each possible score. The score of
the guess is the least of such values.
4. Play the guess with the highest score.
5. Repeat steps #2 to #4 until the sequence is found [6].
9.8 REFERENCES
1. Nelson, T. (2000). A Brief History of the Master Mind Board Game. Available
at http://www.tnelson.demon.co.uk/mastermind/history.html. Accessed on
January 9, 2014.
Mastermind • 167
10
THE MONTY HALL PROBLEM
10.1 BACKGROUND
The Monty Hall Problem (Figure 129) is one of the most well-known
and widely studied problems in the area of puzzles. It is a probability-based
puzzle where the chance of a favorable outcome is to be compared before
and after an event occurs, and then the better of the two situations must be
determined.
The problem is as follows: In a game show, the host asks a contestant to
pick one door out of three, given that one of the doors has a car behind it.
Each of the other two doors has a goat behind it. After the contestant picks
a door, the host opens one of the other two doors to show a goat behind it.
170 • Artificial Intelligence Problems and Their Solutions
It is clear that either of the two choices gives only a chance or prob-
ability of winning the car and does not guarantee a win. Therefore, proba-
bility-based analysis is the key to solving this problem. Also, this problem
involves making decisions. Initially the contestant has to choose a door,
which is very likely a random choice because all three doors have an equal
probability (1/3) of having a car behind them. But after it is revealed that
one of the doors has a goat, the situation changes. The contestant now has
more information than when he or she picked one door out of three. Since
the contestant’s final decision of staying with or switching the chosen door
depends on the original choice and the host’s action, we create a decision
tree to analyze the problem. A tabular version of the decision tree is shown
in Table 14.
Also, since this problem has a small state space in terms of all possible
outcomes of the combination of the contestant’s original decision, the host’s
choice of door, and the contestant’s final decision, we can do an exhaustive
enumeration of the solution state space as shown in Table 14.
Table 14 shows all the possible scenarios for this puzzle. The numbers
1, 2, and 3 represent the three doors. We consider the three possibilities
of the car being behind each door one by one. In each of the three cases
stated above, we further consider three cases or possibilities for the original
choice.
The Monty Hall Problem • 171
For each of the possible initial choices, the host will choose a door hav-
ing a goat, thus reducing the number of doors possibly having a car to just
two instead of three. This leaves the contestant with two choices: either to
stay with the initial choice or switch to the door not opened by the host.
The final choice made by the contestant and the ensuing result are
shown in the last two columns. It is evident that staying with the original
choice guarantees a win if the original choice was correct. And the prob-
ability of the original choice being correct is 1/3 because only one door out
172 • Artificial Intelligence Problems and Their Solutions
of three has a car behind it. On the contrary, the probability of the original
choice being incorrect is 2/3, so in this case switching leads to a better chance
of winning.
We can look at it another way. Say instead of 3 doors, there were 10
doors with a car behind 1 door and goats behind 9 doors. The contestant
chooses a door, and the host reveals 8 doors that have goats. In this case,
should the contestant stay with his or her original choice or switch?
It is clear that initially the probability of opening the correct door is 1/10,
which also means the probability of opening a door with a goat is 9/10. Since,
we are more likely to open a door with a goat initially, switching is more
likely to lead to a win—in this case, a ½ chance of winning.
10.3 SOLUTION
The solution as described in the previous section is that you have more
chances of winning if you switch. This is because you have double the
chances of having a wrong door with your initial choice. The host always
opens a door (that you did not choose) with a goat behind it (as described in
the problem). So after this event happens, we know the car is behind one of
the two other doors and thus there is a 50% chance of the car being behind
either of the two other doors. So staying with the original choice would
mean 1/3 = 33.3% chance of winning, and switching would mean 2/3 = 66%
chance of winning. This is clearly shown in Table 14.
The Monty Hall Problem first appeared in Marilyn vos Savant’s column
in Parade Magazine. Vos Savant, who answers questions and solves puz-
zles submitted by readers, was once listed in the Guinness Book of World
Records as having the highest IQ in the world.
The problem became very popular because it is loosely based on the
popular game show Let’s Make a Deal and was named after the show’s host,
Monty Hall. In response to the question of whether it was better to stay
with the original choice or switch, Vos Savant stated that switching was the
The Monty Hall Problem • 173
10.5 REFERENCES
1. Deaves, R.H. (2007). The Monty Hall Problem: Behind Closed Doors. Lulu.com
Available at http://www.amazon.com/The-Monty-Hall-Problem-Beyond/
dp/1847530788. Accessed on January 10, 2014).
11
RUBIK’S CUBE
11.1 BACKGROUND
Rubik’s Cube (Figure 130) is one of the most popular puzzles in his-
tory. It is a three-dimensional combination puzzle that was invented in 1974
by Ernö Rubik, a Hungarian architect and professor [1]. The cube is made
up of 26 smaller cubes. When considering one of these smaller cubes as a
unit, we can say that the whole cube has dimensions of 3” × 3” × 3”, with 1
smaller cube missing from its center. Together, 9 smaller cubes that make
up one of the faces of the whole cube can be turned into a “layer” that has
the ability to rotate while staying in position. Rubik created the cube in an
176 • Artificial Intelligence Problems and Their Solutions
11.3 SOLUTION
The Parts
As mentioned before, Rubik’s Cube is made up of 26 smaller cubes.
However, they are not identical, as there three different types of these
smaller cubes.
The Corners (in white) (Figure 131)
There are a total of 8 corner cubes, each consisting of three colors.
178 • Artificial Intelligence Problems and Their Solutions
The Layers
By layers, we are referring to the sections of the cube that can be
rotated. A layer consists of 9 smaller cubes that can be rotated as much as
180 • Artificial Intelligence Problems and Their Solutions
360 degrees two-dimensionally. The cube has a total of six layers, and each
will be denoted by a single letter:
The Top (or Up) Layer = U (Figure 135)
The layers are named relative to the faces of the cube that are considered
to be the front and top. For example, if we choose the White Face to be our
182 • Artificial Intelligence Problems and Their Solutions
Front Face and the Red Face to be our Top Face, then the layer considered
as the Left will be different from the layer considered the Left if say the
Blue Face was considered the Front Face.
These denotations will be used to show how a particular layer is to be
rotated in an algorithm. When a letter is shown, that means that the layer
it corresponds to is to be rotated 90 degrees clockwise. Furthermore, an
apostrophe (’) after the letter indicates that the same layer is to be rotated
90 degrees counterclockwise. A chain of these letters will make up an algo-
rithm, and they must be followed in the order given. Here is an example of
an algorithm:
U D F’
This algorithm indicates that the Top Layer should be moved clock-
wise, then the Bottom Layer, and finally the Front Layer should be moved
counterclockwise. You will see that as more small cubes are put into place,
the algorithms used to solve the remaining cubes become more complex.
To begin this solution, we choose the Red Side to be the Top Face. The
Front Face will be determined later.
The first subgoal (Figure 141) is to place the top 4 edge cubes into their
correct positions. As a result, the Top Side should look like a red cross.
Rubik’s Cube • 183
Take note of the issue here. The Red-Green edge has its colors inverted.
To fix this, a particular algorithm must be used.
First, consider the Front Side as the Green Face, with the Top Side
remaining as the Red Face. Next, perform these moves:
F’ U L’ U’
This algorithm will reorient the Red-Green edge to its correct
configuration, while keeping the other three top edges in place.
184 • Artificial Intelligence Problems and Their Solutions
The sub-goal in Figure 143 will not only put the 4 top corner pieces
in the correct place, but it will also complete the Red Face and the entire Top
Layer!
Let’s say we want to begin by putting the Red-Blue-Green corner in its
correct place. Our first step is to bring the corner to the bottom if it is not
already there. First, locate one of the sides that the Red-Blue-Green corner
is on and call that the Front Side. In our case, let’s say that it is located in
between the Yellow and White Faces. We can either choose the Front Face
to be the Yellow Face or the White Face. Let’s choose the White Face to
be the Front Face. The Red-Green-Blue corner can now be located on
the upper left corner of the Front Face. To get it to the bottom without
displacing the Red-White edge, perform this algorithm:
F D’ F’
If we had chosen the Front Face to be the Yellow Face instead, the
Red-Green-Blue corner would be located on the upper left side, and we
would have to perform this algorithm instead:
F’ D F
Whichever algorithm was performed, our target corner should now be
on the Bottom Layer, and the edge we positioned in subgoal 1 should still
be on the Top Layer. Rotate the Bottom Layer until the corner piece is
located in between the Green and Blue Faces. At this point, we can have
one of the three possible states shown in Figures 144 to 146.
Rubik’s Cube • 185
State 1: Make the new Front Face the face that contains the correct
color (which in this case will be the Blue Face). Our target corner should
now be a part of the lower left corner of the Front Face. Then perform the
following algorithm:
L D’ L’
State 2: As with State 1, make the new Front Face the face that con-
tains the correct color (which in this case will be the Green Face). However,
the target corner should now be a part of the lower right corner of the Front
Face. Then perform the following algorithm:
R’ D R
State 3: In this orientation, we cannot properly place the Red-Green-
Blue corner in its correct position. We need to reorient the corner so it
matches State 1 or State 2. Let’s change it to State 1. First, pick the new
Front Face that will make the target corner be a part of its lower left corner
(in this case the Green Face). Then perform the following algorithm:
L D’D’ L’ D
After performing this, the corner piece will be back in between the
Green and Blue Faces and will be oriented as it appears in State 1. Now
simply perform the State 1 algorithm. Do these methods for all four cor-
ners, and you will have achieved subgoal 2.
Subgoal 3 (Figure 147) puts the four center edge cubes in their cor-
rect positions. By the end of this subgoal, the middle layer of Rubik’s Cube
186 • Artificial Intelligence Problems and Their Solutions
Take note of the top color of this edge piece. From the Front Face,
look at the colors of the Left and Right Faces. Whichever color matches the
target edge’s top color determines which algorithm to use next. In this case,
Rubik’s Cube • 187
the Green on the top of the Blue-Green edge matches the Green Face,
which is located on the Right Layer. Therefore, use the following algorithm:
U R U’ R’ U’ F’ U F
After performing this algorithm, the Blue-Green edge will be placed in
its appropriate position in the middle row.
Alternatively, if it were the case that the Green Face was on the Left
Layer, we would use this algorithm:
U’ L’ U L U F U’ F’
One possible issue that can occur is that an edge piece will be placed in
its correct position but oriented incorrectly, as in Figure 149.
After the previous subgoal, the Top Face will be arranged in one of the
four ways shown in Figures 151 to 154.
FIGURE 151 State 1. FIGURE 152 State 2. FIGURE 153 State 3. FIGURE 154 State 4.
In any of these four states, do not consider the color of the corners
whether they are Orange or not. Also, this should still be considered the
Top Face and not the Front Face. In carry out the following algorithms,
you must pick a Front Face so the Top Face appears as one of these figures
when you look at the cube from above.
State 1: The cross is already formed, and you can move on to subgoal 6.
State 2: The only part of the cross is the center. Use the following
algorithm:
F U R U’ R’ F’
State 3: Only three pieces of the cross are in their correct places and
form something like a right angle or a backward “L.” Use the same algorithm
as State 2 for this configuration.
Rubik’s Cube • 189
State 4: Again, only three pieces of the cross are in their correct places,
but this time they form a straight line. For this configuration, use the
following algorithm:
F R U R’ U’ F’
Additionally, you may find that the Top Face looks like Figure 155.
Again, this is not the Front Face but the Top Face. However, make sure
that you pick a Front Face so any of these configurations match what the
Top Face looks like while looking at the cube from above.
Subgoal 6 (Figure 160) is to position the four Top Layer corner pieces
into their correct orientations. At this point, there will be exactly two cor-
ners in correct orientation. From an overhead view of the cube, the Top
Layer will be arranged in one of the two ways shown in Figures 161 and 162.
Rubik’s Cube • 191
The “C” indicates the corner pieces in their Correct orientation. They
are indicated as such because this can apply to any two random corners in
the Top Layer. To see which corners are in correct orientation, the entire
cube must be analyzed. Fortunately, doing this is an easy task. First, analyze
the four corner pieces as they appear. If you do not see that they are in their
correct spots, then rotate the Top Layer 90 degrees and look again. If you
still cannot determine them, rotate the Top Layer 90 degrees once again.
Eventually, it will become obvious which corners are in correct orientation.
However, it is important that once you discover the correct corners, you
must rotate the Top Layer so they are placed in their correct locations rela-
tive to the entire cube.
For this subgoal, the following algorithm must be used in either case:
R’ F R’ B B R F’ R’ B B R R U’
State 1: It is possible that the two correctly oriented corner pieces
will be directly next to each other. First, double check to see if they are in
their correct positions relative to the cube. If not, you must rotate the Top
Face until they are. This is easy to determine, since they are both adjacent
and share two of the same colors. Then pick a Front Face so when you are
192 • Artificial Intelligence Problems and Their Solutions
looking at the Top Face from above, it will appear as in Figure 161 (i.e., the
upper corner pieces). When looking at the Front Face, these pieces should
be all the way in the back of the cube at the top.
State 2: It is also possible that the correctly oriented cubes are directly
across from each other on the Top Layer. At this point we need to bring
the cube into State 1. If the correctly oriented corner pieces appear as they
do in Figure 162 simply use the algorithm above. It does not matter how
the Top Layer is positioned or which face is chosen to be the Front Face as
long as the Top Face we have been using remains as such (in this case the
Orange Face). At this point, your cube will be ready for the final subgoal.
to each other. First, look at two of the incorrect edges, preferably the one
on the Front Layer and one on any Layer adjacent to it (i.e., Left Layer or
Right Layer). At this point you will notice that one of the edges will have to
either be shifted to the left or right to be correctly placed.
Let’s say, for example, we have found the Blue Face to be a part of the
Front Layer. Assume we have the configuration in Figure 164.
We see that the Orange-Blue edge piece needs to be moved to the
Front Layer from the Right Layer, meaning we need to shift it left. There-
fore, use the following algorithm:
F F U L R’ F F L’ R U F F
This will shift the three target edge pieces in a clockwise direction rela-
tive to the Top Layer, which is why we can call this the “clockwise” algo-
rithm
It may also be the case that the cube has the configuration in Figure
165.
Now, we see that the Orange-Green edge needs to be moved from the
Front Layer to the Right Layer and shift it right. Therefore, we use what we
call the “counterclockwise” algorithm:
F F U’ L R’ F F L’ R U’ F F
This will shift the three target edge pieces counterclockwise. Using
either of these algorithms once should place these edges in their correct
positions
State 2: None of the Top Layer edges are correct. It may be the case
that all four Top Layer edges are not in their incorrect positions. If so, then
use any one of the two algorithms above. It will not put all four edges in
their correct positions, but it will put one edge in its correct position, bring-
ing the cube into State 1. At this point, Rubik’s Cube will be completely
solved.
Difficulty
7/10
Complex.
O( n2/log )
Prob.
Int or Intly/ Mode of
Name Rep. HW? Corr? Grn Sz Exec Compr Solv. Flex Opt? Tot
Ext? Extly Conv
Mthd
Img/Txt
Adam Ext. 3/10 Txt w/ Pics Y Y Ideal 8/10 4/10 Subgoals 5/10 N 20/40
Editor
Img/Txt
Animation Ext. 9/10 Txt w/ Pics Y Y Ideal 9/10 8/10 Subgoals 7/10 N 33/40
Editor
Img/Txt
C&P Ext. 4/10 Txt w/ Pics Y Y Ideal 8/10 6/10 Subgoals 6/10 N 24/40
Editor; Hand
Cartoon Img/Txt
Ext. 5/10 Txt w/ Pics Y Y Ideal 8/10 7/10 Subgoals 7/10 N 27/40
Pics Editor; Hand
Img/Txt
Enemy Ext. 8/10 Txt w/ Pics Y Y Ideal 7/10 9/10 Subgoals 7/10 N 31/40
Editor
Magic Img/Txt
Ext. 7/10 Txt w/ Pics Y Y Ideal 7/10 8/10 Subgoals 7/10 N 29/40
Cube Editor; Hand
Img/Txt
Short Ext. 6/10 Txt w/ Pics Y Y Ideal 2/10 3/10 Subgoals 6/10 N 17/40
Editor; Hand
Simple Img/Txt
Ext. 7/10 Txt w/ Pics Y Y Ideal 8/10 9/10 Subgoals 7/10 N 31/40
Cube Editor
Img/Txt
Square Ext. 7/10 Txt w/ Pics Y Y Ideal 6/10 4/10 Subgoals 7/10 N 24/40
Editor
Key
ture of these images is that they are also animated, so when they are clicked,
the layers rotate to show how the specific algorithms are carried out on
command. This increases the solution’s comprehensibility and executability
even further.
To improve this solution even more, the steps of each algorithm should
be depicted along with the animated cubes. This will give the solver a choice
between watching the animation and following the steps of the algorithms
as they are commonly followed.
Each algorithm moves a corner from the top layer to the bottom layer
right below.
Rubik’s Cube • 199
Step 4: Edges
If Orange pieces form a line on top, apply the first algorithm. Then apply
the second.
Step 5: Corners
View the top layer.
Algorithm: R U R’ U R U2 R’
If ONE corner is Orange, move it to the bottom left. Then apply the
algorithm.
or
If TWO corners are Orange, rotate top layer until a Yellow sticker is
on the bottom left, facing front. Then apply the algorithm.
If ZERO corners are Orange, rotate top layer until an Orange sticker
is on the bottom left, facing left. Then apply the algorithm.
Rubik’s Cube • 201
Step 6: Permutations
Roatate the top layer until the same color is in the back. If you don’t
have this, apply the algorithm to get them.
G0 = {U, D, R, L, F, B}
G1 = {U, D, R2, L2, F2, B2}
G2 = {1}
The consequence of reducing the number of phases is that it greatly
increases the number of moves available and the size of the table per phase.
To fix this, he decided “to make pruning tables and use IDA* to solve each
phase,” greatly reducing the state space [11]. To improve the algorithm fur-
ther, Kociemba added a feature that continues the IDA* search even after
the solution is found for a particular phase. This allows the algorithm to find
the solution with the shortest number of steps possible [11].
Although Kociemba’s algorithm is efficient, it is not optimal. In 1995,
Michael Reid analyzed this algorithm and discovered that it takes at most 29
moves to solve the cube with the algorithm [12]. However, in 2010, Tomas
Rokicki, Herbert Kociemba, Morley Davidson, and John Dethridge proved
that Rubik’s Cube can be solved in at most 20 moves, no matter what the
position is. Although there is no specific algorithm that can solve the cube in
20 moves, this was proven by doing extensive research to solve all 43 quin-
tillion possible arrangements. By using simple mathematics programming
and by partitioning these arrangements into particular sets, it took approxi-
mately 35 CPU years to solve every position of Rubik’s Cube, discovering
that it only takes at most 20 moves to solve the cube from any arrangement.
This number is now referred to as “God’s Number,” since it is the opti-
mal number of moves, indicating that “God’s Algorithm” would result in 20
moves [12]. The term “God’s Algorithm” refers to an algorithm that solves
Rubik’s Cube, or any other combinatory puzzle, in the shortest number of
steps. Some algorithms have come close, but none have received the title.
Regardless of which algorithm is used to solve Rubik’s Cube, the complex-
ity for any algorithm in the worst case was found to be O( n2/log(n) ), accord-
ing to a research paper on algorithms for Rubik’s Cube titled “Algorithms for
Solving Rubik’s Cubes” [13].
the mouse. Also, the cube itself can be rotated at will by shifting one of two
scrollbars, allowing the player to get a full view of the cube. Additionally,
the player can choose between solving the easy 2” × 2” × 2” cube up to the
more difficult 5” × 5” × 5” cube. Finally, the player has the option to change
the colors of the cube faces to any color he or she desires.
11.8 REFERENCES
12
THE PRISONER’S DILEMMA
In the movie The Postman Always Rings Twice,** the two lead charac-
ters fall in love and decide to “eliminate” the husband of the female char-
acter. The police have insufficient evidence to obtain convictions. However,
after the murder, the lovers are apprehended by the police and held for
* This section is based on Lucci and Kopec (2013). Artificial Intelligence in the 21st Century.
Mercury Learning, Dulles, Virginia, pp. 130-132.
** The 1981 version is a reproduction of an earlier movie based on the novel by James M.
Cain (1934) that stars Jack Nicholson and Jessica Lange.
208 • Artificial Intelligence Problems and Their Solutions
Prisoner B
A: 1 Year A: 10 Year
Cooperate
Prisoner A
B: 1 Year B: 0 Year
(betray partner)
A: 0 Years A: 5 Years
Defect
B: 10 Years B: 5 Years
A payoff matrix specifies the return to each player for every combination of
actions by the two game participants.
Assume that the two players (that is, the prisoners) in this game are
rational and want to minimize their jail sentences. Each prisoner has two
choices (as did the two characters in The Postman Always Rings Twice):
cooperate with their partner in crime and remain silent or defect by con-
fessing to the police in return for a lesser sentence.
You might notice that this game differs in an important aspect from the
games discussed earlier in this book. To determine a course of action in
the other games and puzzles discussed, you need to know your opponent’s
course of action. For example, if you are moving second in a game of tic-tac-
toe, you need to know where the other player has placed the initial X. This
is not the case in The Prisoner’s Dilemma. Suppose you are the A player
and you choose to defect. However, the B player decides to remain loyal
and chooses the cooperation strategy. In this case, your decision results in
no prison time as opposed to the one-year term had both of you chosen to
cooperate. If your partner chooses to defect, your outcome is still superior
if you choose to defect. In game-theoretic terms, defecting is a dominant
strategy. Because you assume that your opponent in this game is rational,
he or she will arrive at the same strategy.
The strategy {Betray, Betray} shared by the two participants is referred
to as a Nash Equilibrium. A change in strategy by either player results in
a lesser return to them (i.e., more jail time).
As shown in Figure 168, if each player acts more on faith than rational-
ity (faith that their partners would remain loyal), then the total payoff would
exceed the total of 10 prison years accorded by the Nash Equilibrium of
{Defect, Defect}. This strategy of {Cooperate, Cooperate} yields the best
possible outcome in terms of total payoff to the two players. This optimal
strategy is referred to as Pareto Optimal. It should be noted that The
Prisoner’s Dilemma is not a zero-sum game. Why not? In such games, Nash
Equilibrium does not necessarily correspond to a Pareto Optimal game [2].
TABLE 16 Example 1.
Solution:
This is akin to the original Prisoner’s Dilemma, but with a twist. If both
companies advertise, the Nash Equilibrium is if either company advertises.
If both companies advertise or neither company advertises, then the result
is the status quo (1, 1).
Example 3: In New Zealand, newspaper boxes are left unlocked. One
can easily steal a paper (defect). Naturally, if everyone did this, no papers
would remain [2]. Clearly this is an example of the Iterated Prisoner’s
Dilemma, because even though at first it may seem that the “stolen”
newspapers have little effect, over time there would be no newspapers
left to sell.
Example 4: (Tragedy of the Commons): A village has n farmers,
and grassland is limited. Each of these farmers may decide to keep a sheep.
Each farmer obtains some utility from these sheep in the form of wool and
milk. However, the common grassland (the Commons) will suffer some-
what from the sheep grazing there.
Solution: The solution is described below. It was first described by
Hardin in The Tragedy of the Commons [5].
When multiple individuals act independently and they apply their
own self-interest, they will deplete a shared resource. This will occur even
though it is in no one’s long-term interest. Originally formulated in terms
of sheep and common grassland, it can readily be applied to many con-
temporary conundrums. Global climate is one such arena. It is cheaper to
manufacture products if little or no attention is paid to pollution and emis-
sion control, but it is certainly detrimental to the earth’s long-term health.
A nice example for this scenario is available at www.skepticalscience.com
12.4 REFERENCES
4. Lucci, S., and Kopec, D. (2013). Artificial Intelligence in the 21st Century.
Dulles, Virginia: Mercury Learning Inc.
5. Hardin, G. (1968). “The Tragedy of the Commons.” Science (162) 3859:
1243–1248.
CHAPTER
13
MISCELLANEOUS PROBLEMS
T
his chapter contains five smaller problems from different areas, such
as probability, logic, and mathematics. We believe they are sufficiently
intriguing to be of interest and value to any dedicated problem solver.
Cards/Coins in the Dark is a math puzzle and has two variants: one with
a deck of cards and one with a set of 100 coins (Figure 169).
The problem is as follows: You are in a dark room and are given a
deck of 52 cards. You are told that 13 of the 52 cards are faceup and are
distributed throughout the deck. You are asked to divide the deck into two
216 • Artificial Intelligence Problems and Their Solutions
piles consisting of the same number of faceup cards. You cannot distin-
guish between the faceup and facedown cards by feeling them, and also,
since the room is dark, you cannot see the cards. How can you accomplish
this task?
Solution
There are 13 faceup cards. If we randomly divide the whole deck of
cards into two piles, the 13 faceup cards will be divided between the two
piles. Say if the first pile has n faceup cards, then the second pile will have
13 – n faceup cards. So if the first pile had 13 – n faceup cards instead of n
faceup cards, the two piles will have an equal number of faceup cards.
Thus, if the first pile has a total of 13 cards, then it would have 13 – n
facedown cards, and if we flip all the cards in the first pile, we would have
13 – n faceup cards. So the solution is to divide the cards into two piles, one
with 13 cards and one with 39 cards and then flip all the cards in the first
pile. Figures 170 to 172 show this solution.
Pile 1
Pile 2
Pile 1
Pile 2
The coins version of this problem has 100 coins on a table in a dark
room. Of the 100 coins, 10 coins have heads-up, and the goal is to divide the
coins into two piles with an equal number of coins heads-up.
The solution is similar to that of the cards version of the problem. We
choose any 10 coins to form the first pile and flip all of them over. The
remaining 90 coins form the second pile.
If the first pile originally had n coins with heads-up, the second pile will
have 10 – n coins heads-up. After all the coins in the first pile are flipped
over, the first pile will also have 10 – n coins.
13.1.3 References
1. http://www.calpoly.edu/~mcarlton/riddles.html
(July 10, 2013)
2. http://wordplay.blogs.nytimes.com/2013/05/20/
dark-2/ (July 10, 2013)
The Ten Pirates and Their Gold Problem has been posed for over 20
years (Figure 173), but it gained attention when some serious mathema-
ticians (Ian Stewart) and computer scientists (Stephen M. Omohumdro)
tackled it with some variations in the late 1990s. The problem is as follows:
Ten pirates find a buried treasure of 100 pieces of gold (Figure 174). The
challenge is to divide the gold in some desirable way according to some con-
straints (rules). The first constraint is that Pirate 1 is the lead pirate; Pirate
2 is the second in charge; Pirate 3 is the third most powerful; and so on.
The pirates have a scheme for dividing the money. They agree that the first
pirate (P1) will make a proposal for how the money is to be divided. If 50%
or more of the pirates agree with the P1 system, it will be put into effect. If
not, then P1 will be killed, and the next most powerful pirate becomes the
lead pirate. Now, again with one fewer pirate, the process repeats. The new
lead pirate, P2, now suggests a new process for divvying up the gold. It will
Miscellaneous Problems • 219
be voted on, with a 50% vote needed for the leader’s suggestion to pass; less
than 50% results in the death of the lead pirate.
All the pirates are very greedy and savvy, so they will vote against a
proposal if it means they will get more gold if the proposal fails, and thus a
lead pirate is killed. They will never vote for a proposal that will give them
less gold or no gold.
When you first hear this problem and consider possible solutions, you
might think the following: Let’s say the lead pirate (P1) wants to be pretty
fair and takes 19 pieces of gold, offering 81 pieces of gold to the remaining
9 pirates (9 each). The problem is that he needs 4 pirates to agree with him.
And if the 4 pirates see a way to get more gold, they will not vote to go with
him.
The lead pirate taking 19 and the rest taking 11 seems pretty fair, but
the 4 voting pirates will see a better way for them. If P1 is eliminated (no
vote in favor), then a nice scenario might seem to be P2 gets 12 and the
others get 8 × 11 (= 88). This seems very reasonable and equitable, but
pirates are not known for being equitable. So the pirates might eliminate
P2, seeing a scenario like P3 = 16, and the others get 7 × 12 (= 84). Still,
there will be pirates who see a way for them to get more gold for themselves
who would exercise their veto vote to possibly achieve this.
Using this approach, we can see the following logic could lead to some
real results: Imagine if there were only two pirates, P1 and P2 (Figure 175).
P1 would want to take all the gold (100 pieces), leaving P2 with no gold and
no say about it (the 50% rule).
P1 P2
Now let us consider the situation with three pirates: P1, P2, and P3
(Figure 176). Pirates are not stupid. They would realize that if they vote
against you, P2 gets all the gold and P3 gets no gold after you are gone.
Knowing this, P3 will accept your offer of 1 piece of gold, with no gold to
P2, P2 will not be happy, but your proposal will pass. With four pirates, the
same proposal (P3 gets 1 coin) will pass, with P3 giving you the one vote you
need to pass (50%) (Figure 177).
P1 P2 P3
P1 P2 P3 P4
The same logic applies to up to 10 pirates, whereby you would give one
piece of gold to P3, P5, P7, and P9 and keep the other 99 pieces for your-
self. Those four pirates would support your proposal, since otherwise they
would receive no gold if your proposal fails.
About the time of Stewart’s article in 1999, Steven Omohundro took
the problem to another level by asking what happens if there are not only
10 pirates but as many as 200 or 500? He concluded that with 200 pirates,
P200 will continue by offering nothing to odd-numbered pirates from P1 to
P199 and one gold coin to even-numbered pirates P2 through P198.
However, the situation gets complicated if we go beyond 200 pirates,
as P201 and P202 will find themselves lacking sufficient “bribing power”
to get support. Matters get even more complicated as we consider 203,
204, . . . , 207 pirates. Omohundro’s conclusion, which Ian Stewart shares
in the article below, is that as we approach 500 pirates, a pattern that con-
tinues indefinitely emerges.
Pirates who can make winning proposals (always to give themselves
nothing and to bribe 100 fellow pirates) are separated from one another by
ever-longer sequences of pirates who will be thrown overboard no matter
what proposal they make—and whose vote is therefore ensured for any
fiercer pirate’s proposal. The pirates who avoid this fate are P201, P202,
P204, P208, P216, P232, P264, P328, P456, and so on—pirates whose num-
ber equals 200 plus a power of 2.
REFERENCE
Stewart, I. (1999). “A Puzzle for Pirates.” Scientific American, 280 (5): May
1999, 98–99. Available at http://omohundro.files.wordpress.com/2009/03/
stewart99_a_puzzle_for_pirates.pdf /. Accessed on January 10, 2014.
222 • Artificial Intelligence Problems and Their Solutions
Now, here is the question: How many hands did Halmos’s wife shake?
Let’s see what we already know (Figure 180). We’ll start by considering
the person who claims to have shaken 8 hands and call this person A. Whose
hands did A shake? Necessarily, A shook hands with everyone else present,
apart from his or her spouse (whom we call A(w)). So everyone besides A’s
spouse {A(w)} shook at least one hand—namely, A’s hand (Figure 181).
So who is the person who shook 0 hands? Since everyone except A’s
spouse shook at least one hand, the person who shook 0 hands must be A’s
spouse, A(w) (Figure 182).
Now consider the person who
shook 7 hands, whom we’ll call B.
B didn’t shake hands with himself or
herself or with his or her spouse {B(w)}
0 Handshakes or with A(w) (because A(w) shook no
hands). That leaves only 7 other people,
FIGURE 182 Person A’s Wife—0 Shakes so B shook hands with everyone else
except B and his or her own spouse {B(w)}
(Figure 183). And each of these people also shook hands with A, mean-
ing that all of these people shook at least two hands: A’s and B’s. So the
only person left who could have shaken just 1 hand is B’s spouse, B(w)
(Figure 184). So just as the person who shook 8 hands is married to the
person who shook 0 hands, the person who shook 7 hands is married to
the person who shook only 1 hand. We can now see a pattern evolving in
the solution.
Applying the same logic one more time shows that the person who
shook 5 hands, D, is married to the person who shook 3 hands, {D(w)}
(Figures 187 and 188).
What does this leave us? We know that all the possible people who gave
the answers 0, 1, 2, 3, 5, 6, 7, and 8 are all married to other people who
answered Halmos’s question. The only person who is not married to one
of the people who answered the question is the one who answered 4—and
that must be Halmos’s wife {H(w)}. So Halmos’s wife (H(w)) shook 4 hands,
and it follows that Halmos (H) did, too (Figures 189 and 190).
REFERENCE
Solution
There is a 50% chance that the 100th passenger will get to sit in his or
her assigned seat. With such a large number of people entering the plane,
and the 100th passenger entering last, this answer seems implausible!
However, with an analytical approach and some logic, the solution can be
easily understood.
A common way to solve this riddle is to mathematically determine
the chance that each person sits in his or her assigned seat, but the math
gets complicated quickly. However, we can easily come to our answer by
analyzing the possibilities that can occur and the effects caused by those
possibilities.
Miscellaneous Problems • 229
For this solution, we’ll call a passenger Pn, where n represents that per-
son’s place in line. For example, the person who is fifth in line is P5.
We begin by making two observations:
1. If any of the first 99 people sit in P100’s assigned seat, P100 WILL NOT
get to sit in his seat. This observation should be obvious, since somebody
else sitting in her seat means he cannot sit in it.
2. If any of the first 99 people sit in P1’s seat, P100 WILL get to sit in his
seat. This observation is not as obvious. To make things clear, let’s say, for
example, that P1 sits in P2’s seat. This means that P2 cannot sit in his as-
signed seat, so he must sit in another. Potentially, P2 will sit in any other
seat he chooses. Let’s say P2 sits in P3’s seat. Then P3 will be in the same
predicament that P2 was in and, without an assigned seat, will randomly
sit anywhere he wants. Let’s then say that P3 sits in Pn’s seat. All of the
passengers between P3 and Pn will get to sit in their assigned seats, but
Pn will find his seat occupied and therefore will randomly sit in any other
passenger’s unoccupied seat. This will continue until a passenger—say,
P50—happens to sit in P1’s seat. Once this happens, the remaining pas-
sengers will not find their seats occupied and will now be able to freely
sit in their assigned seats. P51 will sit in his assigned seat, P52 will sit in
her assigned seat, and so forth. Therefore, P100 will get to sit in his or
her own seat.
So to summarize these two observations, if P100’s seat becomes occu-
pied, P100 will not get her seat. If P1’s seat becomes occupied, P100 will
get her seat. Therefore, only these two factors determine whether or not
P100 will get his or her seat. As for the rest of the seats, we can see from our
observations that they make absolutely no difference in determining P100’s
last seat. When the other passengers choose seats that do not belong to P1
or P100, they are just prolonging the final determination.
It is important, however, to understand that the probability of a passen-
ger randomly choosing a specific seat is exactly the same for every seat. For
example, when P1 enters the plane, he has 100 seats to choose from and
therefore has a 1/100 chance that he will sit in his own seat and 1/100 chance
that he will sit in P100’s seat. If he happened to sit in P2’s seat, then P2 will
have 99 seats to choose from. Therefore, there will be a 1/99 chance that he
will sit in P1’s seat and a 1/99 chance that he will sit in P100’s seat. Gener-
ally, if there are n remaining seats available on the plane, the passenger that
is next in line will have a 1/n chance he will sit in P1’s seat and a 1/n chance
230 • Artificial Intelligence Problems and Their Solutions
he will sit in P100’s seat. Therefore, the chance of any passenger sitting in
either P1’s seat or P100’s seat will always be equally likely.
To summarize this solution:
1. P100 will get her assigned seat if any other passenger sits in P1’s seat.
2. P100 will not get her assigned seat if any other passenger sits in P100’s
seat.
3. 1 and 2 are the only two choices that determine P100’s seating, and they
are always both equally likely to happen.
Therefore, P100 will have a 50% chance that she will be seated in her
assigned seat if P1 randomly sits anywhere.
REFERENCE
group of people in a room. How many people do you need in this group so
there is more than a 50% chance that two of these people have the same
birthday (month and day)? Unlike The Random Airline Seats Problem, this
problem requires a better understanding of the laws of probability.
Solution
The answer is 23. In a group of 23 random people, there is a 50.76%
chance that two or more of them have the same birthday! Although this
does not seem to make sense at first, it should become clearer when we
present some probability theory.
The question is asking about the probability with regard to two random
people in a group of people. A common misconception is that the problem
asks for the odds that two specific people will have the same birthday. A
direct computation to solve the problem is relatively complex. However,
to simplify the problem, we will first calculate the probability that no two
people have the same birthday [1].
Let’s assume that February 29 does not exist and that there are only
365 days in every year, meaning there are a total of 365 possible birth dates.
Say we have only 1 person, whom we will call Person A. Because Person A
is only one individual, her birthday could be any one of 365 days, and there
is no chance that her birthday will be the same as anyone else’s. Therefore,
there is a 365/365 = 1 = 100% probability that Person A will not have the
same birthday as someone else.
Let’s now add a second person to our group, named Person B. Since
Person A already exists in the group, there is one fewer possible birthday
that Person B could have whereby B does not match any other birthdays in
the group, which is basically Person A’s birthday. Therefore, the probability
that Person B does not have the same birthday as A is 364/365. Now we
need to find the probability that the group does not have matching birth-
days. It is important to take note that a person having a certain birthday
does not depend on another person having that same birthday. Therefore:
REFERENCE
Strogatz, S. (2012). “It’s My Birthday Too, Yeah.” New York Times, October 1.
Available at http://opinionator.blogs.nytimes.com/2012/10/01/its-my-birthday-
too-yeah/?_r=0. Accessed on January 9, 2014.
CHAPTER
14
CONCLUSION: TOWARD A THEORY
FOR PROBLEM SOLVING
Knowledge Problem-Solving
No. Problem Problem Type
Representation Strategies
The Search tree,
Logic, constraint Solving subgoals,
Missionaries state transition
1 satisfaction backtracking,
and Cannibals diagram, problem
problem symmetry, search
Problem state space matrix
The 12 Coins Logic, Problem reduction,
2 Search tree, table
Problem mathematical recursion
Mathematical, Generate and test,
Knowledge
constraint deduction, arithmetic,
3 Cryptarithms table, constraint
satisfaction backtracking, forward
hypergraph
problem checking, heuristics
The Red Don- Solving subgoals,
4 Pictorial Sliding block puzzle
key Puzzle bidirectional search
Solving subproblems;
numerous methods,
Graphical, row
5 The 15 Puzzle Sliding block puzzle including disjoint
by row
patterns, database
heuristics
Graph—
The Knight’s Graphical; Tessel- Patterns and
6 Hamiltonian Cycle
Tour Problem lations heuristics
Problem
Characters or Logic, Deduction, Five-
7 Mastermind
Graphic combinatorics Guess Algorithm
Subgoals, steps,
9 Rubik’s Cube Pictorial 3 blocks; patterns
algorithms
Logic, constraint
The Prisoner’s Deduction, iterative,
10 Table satisfaction
Dilemma strategical thinking
problem
solve it right away without looking into its smaller versions. As discussed in
Chapter 4, we started from the most elementary form of this problem to
understand the constraints of the problem and the best way of dividing the
coins. The pitfalls of dividing the coins into two equal groups were evident
from the four coins version of the problem. Solving the reduced versions
of the problem helped us get familiar with the nuances of the prob-
lem and differentiate between good and bad weighings.
Furthermore, one of the important techniques used was to maximize
the amount of knowledge gained from earlier weighings. Due to the
constraint of trying to minimize the number of weighings, sometimes we
had to find the odd coin and its relative weight in a single weighing.
Recursion was another important techniques used as we had solved
the smaller and elementary versions of The 12 Coins Problem. Recursion
helped reduce the problem continually until it was converted to its most
elementary form and solved directly.
Furthermore, the use of recursion facilitates the conversion of exten-
sional solutions for subproblems (e.g., 3, 4, 5, 6 coins) to a compact inten-
sional formula that can be generalized for all numbers of coins [17].
14.2.3 Cryptarithms
Due to the nature of arithmetic operations, there are some clues inher-
ent in cryptarithms that can be spotted easily, such as the occurrence of 0, 1,
and 9. These clues serve as a starting point for solving the problem. Graphs
representing the constraints of the problem help in uncovering the
relationships and dependencies between the variables of the prob-
lem. Problems like cryptarithms call for the use of a variety of techniques in
various stages of the problem-solving process. This is also true for real-life
problems where one technique may not offer a complete solution.
Initially, clues and carryovers can help make some progress. After
that, the problem solvers veer toward narrowing down the domains of the
variables, eliminating some values that will ultimately lead to dead ends.
This saves time and avoids unnecessary calculations. When the domain of
some variables is low enough to allow an exhaustive search, the generate-
and-test technique can be used to facilitate some assumptions, proceed,
and backtrack if further search is impossible. Such values are eliminated,
and the remaining values are tested.
Conclusion: Toward A Theory For Problem Solving • 237
The 15 Puzzle has been around for nearly 150 years and has probably
been subjected to more applications of AI search techniques than any other
problem in this book. Heuristics such as “the number of tiles out of place”
or “The Manhattan Distance,” coupled with algorithms such as depth-first
search, breadth-first search, A* algorithm, and, most recently the disjoint
pattern database method, have routinely used The 15 Puzzle as a test bed.
We have learned from the MHWC solution that systematic approaches
developing the solution row by row are most welcome and easy to compre-
hend.
The Knight’s Tour is also a very old problem that has been the subject of
study for thousands of years. The remarkable fact is that solutions must be
identified from 4 × 1051 possible sequences. A number of techniques have
been used to identify solutions, including subproblems, exhaustive enumer-
ation, heuristics, patterns, and others. There is also some reminder of the
90 – 10 rule in AI. That is, a few heuristics take care of most of the problem
space (90%), and then a number of new heuristics (or rules) must be devel-
oped to handle 10% of the problem space. In this case, the heuristic that
always suggests choosing edge squares is effective most of the time—until
it isn’t. The problem solver must learn those special cases.
14.2.7 Mastermind
This too has been a familiar problem for many years. It seems
like Rubik’s Cube, akin to cell phones, texting, apps, and so forth, is a
problem more suitable for young people than adults. We believe that the
presentation and discussion of solutions to “The Cube” in Chapter 11 can
provide insights for those heretofore stupefied by it. Of course, no learn-
ing can come without some attention and work. It is a classic example of
illustrating the importance of being able to tackle problems by identifying
and solving subgoals.
The Ten Pirates and Their Gold, for example, sets the stage for thinking
about and representing solutions to The Prisoner’s Dilemma.
Donald Michie and Danny Kopec first proposed the concept of the
Human Window.* It states that the solutions to difficult, AI-type problems
must meet certain criteria to fall within the bounds of the Human Window.
As originally presented in Shweta’s thesis, they need to be correct, compre-
hensible, executable, and of a moderate grain size. It was to Dr. Kopec’s
great joy that some 30 years later, Chris Pileggi performed the study of
Human Window solutions on The Missionaries and Cannibals Problem,
cryptarithmetics, The 12 Coins Problem, The Knights Tour Problem,
The 15 Puzzle, and The Red Donkey Puzzle) for his senior thesis project.
Pileggi’s work was extremely impressive and provided the first application
of Michie’s ideas to real, mainstream problems and their solutions.
Shweta Shetty assembled and studied the solutions to the problems in
this book. As we can see from the Human Window analysis of these solu-
tions, humans are comfortable with solutions that are graphical, not too
short or too long, easy to comprehend and execute, testable, and applicable
to every problem state.
Furthermore, we now understand that even though we believe we have
identified the best solutions to a well-known set of AI problems, this is not
enough. Future work needs to focus on how Human Window solutions can
best be presented to human subjects. Clearly, with the current and likely
future generations, even graphical approaches with rules (on paper) will not
suffice. Notions of active participation in learning (patterns) and execution
(performance) are necessary. Video (possibly interactive) or animated
presentation of our solutions would seem like the best next step in pursuing
this research.
* Michie liked to credit Michael Clarke for the notion, but it was Michie who indeed wrote
more about it and developed the concept via Dr. Kopec’s Ph.D. thesis.
Conclusion: Toward A Theory For Problem Solving • 241
K Mastermind
Kavyalankara (Sanskrit work), 134 background, 151–152
Kinsey, Ernest, 110 best machine solution, 165–166
The Knight’s Tour Problem human problem solving, 164
background, 133–134 Human Window analysis of solutions,
best machine solution, 148–149 164–165
human problem solving, 142 overview, 3
Human Window analysis of solutions, playable program, 166
142–147 problem-solving techniques, 152–153
overview, 2–3 solution, 153–163
playable program, 149 Theory for Problem Solving, 238–239
problem-solving techniques, Meirowitz, Mordecai, 151
134–135 MHWC. See Most Human
solution, 135–142 Window-Compatible
Theory for Problem Solving, 238 Michie, Donald, 22
Knowledge representation, 10 Minimum remaining values (MRV)
Knuth, Donald, 238 heuristic, 83
Kociemba, Herbert, 202, 203 The Missionaries and Cannibals Problem
Kopec, D., 23, 210 analysis of solution, 41–42
background, 31–32
L best machine solution, 48
LCV. See Least constraining value choosing an appropriate representation,
Least constraining value (LCV), 83 32–34
Least Human Window-Compatible human problem solving, 38–41
(LHWC), 23 Human Window analysis of solutions,
Cryptarithms, 87–89 42–48
The 15 Puzzle, 126–128 overview, 2
The Knight’s Tour Problem, 145–147 playable program, 49
The Missionaries and Cannibals Problem, solution, 34–38
45–48 Theory for Problem Solving, 235
The Red Donkey Puzzle, 104–106 The Monty Hall Problem
Rubik’s Cube, 198–201 background, 169–170
The 12 Coins Problem, 66–68 human problem solving, 172–173
LHWC. See Least Human overview, 3
Window-Compatible problem-solving techniques, 170–172
Lloyd, Samuel, 110 solution, 172
Logically enumerated solution, 66–68 Theory for Problem Solving, 239
Most Human Window-Compatible
M (MHWC), 23
Magic constant, 146 Cryptarithms, 85–87
Manhattan distance heuristic, 129 The 15 Puzzle, 126
Master cube, 176 The Knight’s Tour Problem, 144–145
250 • Index