Tuesday 15 July 2014

math - Making a cryptaritmetic solver in C++ -


I am planning a C ++ program that takes 3 strings that represent cryptimetric puzzles. For example, two, two, and four given, the program will get digit replacements for each letter such as mathematical expression

  TWO + TWO ------ FOUR   

Correct, with the input, rightly considered one way to go about this will definitely be just for tremendous force, assigning every possible replacement for each letter with nested loop, Try yoga again, until the answer The end is not available.

My idea is that although it is very inadequate, the underlying loop-check thing can be a viable (or necessary) way of going - a series of cuts to limit each one's domain After variables I am getting hard work to imagine this, but will it be appropriate for a first time to consider a normal / padded structure (each X represents an essentially different digit, and each is a continuous issue, Which in this case, would be either 0 or 1)? :

 CCC ..... CCC XXX ..... XXXX + XXX ..... XXXX ---------------- cxxx ...................   

Keeping this in mind, consider some more plan:

- However The principal zero will not be given in the problem, I may add sufficiently to those people where the appropriate things are also on the outside / match operand.

- I am thinking that I should start with a set of 0-9 potential values ​​for each letter, possibly stored in the 'Domain' table as vectors, and the form of deduction For example, if I see some letters like this then

  AC - A   

, I can tell That is zero and it eliminates all other value from my domain i am very good I think about the deduction, but to normalize them for all types of small situations and putting it into the code seems very difficult at first glance.

- Let me know that I have many good There is a series of cuts, which runs through things and boots many values ​​from the domain table, I think I still want a loop on everything and I hope that the state space It is small enough to produce a solution in the right time but it seems that it is important to be more than that! - Maybe to set some clever equations or some

tips with those lines are appreciated!

Cryptimetric issues are classic. In fact, what you need to do, obstacles are generated based on your program input, as if you end up with the following using the given examples:

  O + O = 2O = R + 10Carry1W + W + Carry 1 = 2W + Carry 1 = U + 10 Carry2T + T + Carry2 = 2T + Carry2 = O + 10 Carry3 = O + 10F   

Generalized pseudocode: In the range of small inputs, or

  in the equivalent of input, if they are the same length: Small Inpu [I] + Longer inch 2 [i] + carry [i] = result [i] + 10 * carry [i +1] // [0] = carry more for long input, if it is long: Long Term Input [i] + Carry [i] = Result [i] + 10 * Carry [i + 1]   

Additional constraints based on the definition of the problem:

  Range (Points) == {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Range (Oxygenary Carriage) == {0, 1}  < / Pre> 

For your example:

  range (O, W, T) == {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Category (carry1, carry2, f) == {0, 1}   

Once you have generated Or the obstacles to restrict your search location, you can run on the search area is described in the article written as you can use the CSP resolution techniques and determine its solution (if one exists). (Local) concept of sustainability is very important here and by taking advantage of it you can greatly reduce the search space for CSP.

As a simple example, note that cryptrifithic is usually the leading zero, which means that the result is final with both digits, the last digit, i.e. the last lex, 1 should be (in your example , It means F == 1 ). This obstacle can be propagated backwards, because it means that 2T + Carry2 == O + 10 ; In other words, the minimum value for T should be 5, since Carry2 can be found at maximum 1 and 2 (4) + 1 == 9 search (min-conflict) Algorithm, etc.), but I will not convert this reply to a full CSP class, so I will leave you in further investigation.

(Note that you can not make assumptions like A + C = A -> C == 0 The number to be 9 and the carrying number is 1. In the column it means that C will be limited to the domain {0, 9} in general, However, you were not completely with that.)

No comments:

Post a Comment