You are on page 1of 9

Crypt-arithmetic : Crypt-arithmetic is the science and art of creating and solving cryptarithm.

A cryptarithm is a genre of mathematical puzzle in which the digits are replaced by letters of the alphabet or other symbols. The invention of Crypt arithmetic has been ascribed to ancient China. This art was originally known as letter arithmetic or verbal arithmetic. In India, during the Middle Ages, were developed the arithmetical restorations or "skeletons" a type of cryptarithm in which most or all of the digits have been replaced by asterisks. The worlds best-known Cryptarithmetic puzzle is undoubtedly the puzzle shown in Figure :

This was first introduced by H.E. Dudeney and was first published in the July 1924 issue of Strand Magazine associated with the story of a Kidnappers ransom demand [1]. Modernization, by introducing computers and the Internet, is making quite an impact on Crypt arithmetic and it has already become a standard AI problem because it characterizes a number of important problems in computer science area. Cryptaritmetic is a suitable example of Constraint Satisfaction Problem. Instead of providing description, a Crypt arithmetic problem can be better described by some constraints How To Solve a Cryptaritmetic Puzzle : 1. Preparation Rewrite the problem, expanding the interlinear space to make room for trial numbers that will be written under the letters.

For example, the puzzle SEND + MORE = MONEY, after solving, will appear like this: SEND 9567 +MORE 1085 --------MONEY 10652 2. Remember Cryptaritmetic conventions
y y y y y

Each letter or symbol represents only one digit throughout the problem; When letters are replaced by their digits, the resultant arithmetical operation must be correct; The numerical base, unless specifically stated, is 10; Numbers must not begin with a zero; There must be only one solution to the problem.

Sample Example : SEND +MORE -------------MONEY is a cryptarithmetic problem. Each letter must be given a digit value (0 through 9), with M 0. No two letters must have the same value. The sum of the digits must be as shown in the problem. Solution: D = 7, E = 5, M = 1, N = 6, O = 0, R = 8, S = 9, Y =2. 9567 +1085 --------------10652

Constraint Satisfaction Problem In artificial intelligence and operations research, constraint satisfaction is the process of finding a solution to a set of constraints that impose conditions that the variables must satisfy. A solution is therefore a vector of variables that satisfies all constraints. As originally defined in artificial intelligence, constraints enumerate the possible values a set of variables may take. Informally, a finite domain is a finite set of arbitrary elements. A constraint satisfaction problem on such domain contains a set of variables whose values can only be taken from the domain, and a set of constraints, each constraint specifying the allowed values for a group of variables. A solution to this problem is an evaluation of the variables that satisfies all constraints. In other words, a solution is a way for assigning a value to each variable in such a way that all constraints are satisfied by these values. Thus Constraint Satisfaction Problem (CSP) consist of:
y y y

a set of variables X={x1,...,xn}, for each variable xi, a finite set Di of possible values (its domain), and a set of constraints restricting the values that the variables can simultaneously take.

A solution to a CSP is an assignment of a value from its domain to every variable, in such a way that every constraint is satisfied. We may want to find:
y y y

just one solution, with no preference as to which one, all solutions, an optimal, or at least a good solution, given some objective function defined in terms of some or all of the variables.

Solutions to CSPs can be found by searching systematically through the possible assignments of values to variables. The reasons for choosing to represent and solve a problem as a CSP rather than, say as a mathematical programming problem are twofold. :
y

Firstly, the representation as a CSP is often much closer to the original problem: the variables of the CSP directly correspond to problem entities, and the constraints can be expressed without having to be translated into linear inequalities. This makes the formulation simpler, the solution easier to understand, and the choice of good heuristics to guide the solution strategy more straightforward.

Secondly, although CSP algorithms are essentially very simple, they can sometimes find solution more quickly than if integer programming methods are used.

CSP Representation : A CS problem is usually represented as an undirected graph, called Constraint Graph where the nodes are the variables and the edges are the binary constraints. Unary constraints can be disposed of by just redefining the domains to contain only the values that satisfy all the unary constraints. Higher order constraints are represented by hyper arcs. In the following we restrict our attention to the case of unary and binary constraints. We may want to solve the following problems with a CSP : y determine whether or not a model exists y find a model y find all of the models y count the number of models y find the best model, given some measure of model quality y this is now an optimization problem y determine whether some property of the variables holds in all models Methods for Solving CSPs : We consider three solution methods for constraint satisfaction problems, Generateand-Test, Backtracking [possibly Dependency Directed], and Consistency Driven. 1. Generate and Test We generate one by one all possible complete variable assignments and for each we test if it satisfies all constraints. The corresponding program structure is very simple, just nested loops, one per variable. In the innermost loop we test each constraint. In most situation this method is intolerably slow. 2. Backtracking We order the variables in some fashion, trying to place first the variables that are more highly constrained or with smaller ranges. This order has a great impact on the efficiency of solution algorithms and is examined elsewhere. We start assigning values to variables. We check constraint satisfaction at the earliest possible time and extend an assignment if the constraints involving the currently bound variables are satisfied.

The following is an easy way to do dependency directed backtracking. We keep track at each variable of the variables that precede it in the backtracking order and to which it is connected directly in the constraint graph. Then, when instantiation fails at a variable, backtracking goes in order to these variables skipping over all other intermediate variables. Notice then that we will backtrack at a variable up to as many times as there are preceding neighbors. [This number is called the width of the variable.] The time complexity of the backtracking algorithm grows when it has to backtrack often. Consequently there is a real gain when the variables are ordered so as to minimize their largest width. 3. Consistency Driven Consistency Based Algorithms use information from the constraints to reduce the search space as early in the search as it is possible. Here is a useful definition: A CS problem is i-consistent iff for any choice of domains Dj1, Dj2, .., Dji and for any choice of values in the first i-1 domains there is a value in Dji such that the ituple consisting of all these value will not violate any constraint, i.e. It is consistent. When a CS problem is i-consistent for i equal to one, we say that the problem is Node-Consistent; when i is two, we say the graph is Arc-Consistent. CSP as Incremental Approach with Example It is fairly easy to see that a CSP can be given an incremental formulation as a standard search problem as follows : 1. Initial state: the empty assignment fg, in which all variables are unassigned. 2. Successor function: a value can be assigned to any unassigned variable, provided that it does not conflict with previously assigned variables. 3. Goal test: the current assignment is complete. 4. Path cost: a constant cost (e.g., 1) for every step. Every solution must be a complete assignment and therefore appears at depth n if there are n variables. Furthermore, the search tree extends only to depth n. For these reasons, depth first search algorithms are popular for CSPs. The simplest FINITE DOMAINS kind of CSP involves variables that are discrete and have finite domains. Map-coloring problems are of this kind.

Example :

Constraint graph : The nodes of the graph correspond to variables of the problem and the arcs correspond to constraints. Suppose that, we are looking at a map of Australia showing each of its states and territories, as in Figure 5.1(a), and that we are given the task of coloring each region either red, green, or blue in such a way that no neighboring regions have the same color. To formulate this as a CSP, we define the variables to be the regions: WA, NT, Q, NSW, V , SA, and T. Variables WA, NT, Q, NSW, V, SA, T Domains Di = {red,green,blue} Constraints: adjacent regions must have different colors e.g., WA NT, or (WA,NT) in {(red,green),(red,blue),(green,red), (green,blue),(blue,red),(blue,green)} The constraints require neighboring regions to have distinct colors; for example, the allowable combinations for WA and NT are the pairs {(red; green); (red; blue); (green; red); (green; blue); (blue; red); (blue; green) }

(The constraint can also be represented more succinctly as the inequality WA 6= NT, provided the constraint satisfaction algorithm has some way to evaluate such expressions.) There are many possible solutions, such as {WA=red;NT =green;Q=red;NSW =green; V =red; SA=blue; T =red } Infinite domain : Discrete variables can also have infinite domainsfor example, the set of integers or the set of strings. For example, when scheduling construction jobs onto a calendar, each jobs start date is a variable and the possible values are integer numbers of days from the current date. With infinite domains, it is no longer possible to describe constraints by enumerating CONSTRAINT all allowed combinations of values. Unary Constraint : The simplest type is the unary constraint, which restricts the value of a single variable. For example, it could be the case that South Australians actively dislike the color green. Every unary constraint can be eliminated simply by preprocessing the domain of the corresponding variable to remove any value that violates the constraint. Binary Constraint : A binary constraint relates two variables. For example, SA 6= NSW is a binary constraint. A binary CSP is one with only binary constraints;

Solutions are complete and consistent assignments, e.g., WA = red, NT = green,Q = red,NSW = green,V = red,SA = blue,T = green

Example of Cryptarithmetic : It is usual to insist that each letter in a cryptarithmetic puzzle represent a different digit. For the case in Figure 5.2(a)), this would be represented as the six-variable constraint Alldi_ (F; T; U;W;R;O). Alternatively, it can be represented by a collection of binary constraints such as F 6= T. The addition constraints on the four columns of the puzzle also involve several variables and can be written as : O + O = R + 10 _ X1 X1 +W +W = U + 10 _ X2 X2 + T + T = O + 10 _ X3 X3 = F Where X1, X2, and X3 are auxiliary variables representing the digit (0 or 1) carried over into the next column. Higher-order constraints can be represented in a constraint hypergraph, such as the one shown in Figure 5.2(b). The sharp-eyed reader will have noticed that the Alldiff constraint can be broken down into binary constraintsF 6= T, F 6= U, and so on.

Solution :

Algorithm : The algorithm has the following steps: 1. Choose any variable as the root of the tree, and order the variables from the root to the leaves in such a way that every nodes parent in the tree precedes it in the ordering. (See Figure 5.10(b).) Label the variables X1; : : : ;Xn in order. Now, every variable except the root has exactly one parent variable. 2. For j from n down to 2, apply arc consistency to the arc (Xi;Xj), where Xi is the parent of Xj , removing values from DOMAIN[Xi] as necessary. 3. For j from 1 to n, assign any value for Xj consistent with the value assigned for Xi, where Xi is the parent of Xj . There are two key points to note. First, after step 2 the CSP is directionally arcconsistent, so the assignment of values in step 3 requires no backtracking. (See the discussion of k-consistency on page 147.) Second, by applying the arc-consistency checks in reverse order in step 2, the algorithm ensures that any deleted values cannot endanger the consistency of arcs that have been processed already. The complete algorithm runs in time O(nd2).

You might also like