mark Richardson wrote:
Raphael Collet wrote:
Dear Mark,

The trick is to constrain "EF" to be the smallest factor in the product. Palindromes you find are duplicated because swaping the factors in the product gives the same palindrome. Simply restrict the search space to avoid that.

I suggest to first simplify a bit your model. In my view, only 4 variables are relevant to the problem: the first two digits in the palindrome (say A and B), and the factors of the product (say X and Y). Those variables are constrained as:

    [A B] ::: 0#9             % those are digits
    [X Y] ::: 0#99            % those are two-digit numbers
    A >: 0                    % A is nonzero
    1001*A + 110*B =: X*Y     % ABBA is equal to X * Y
    X =<: Y                   % break symmetry

I would define the solution as:

    sol([A B B A] X Y)

Note that duplicates may still appear, but this time because the factorization of the palindrome might not be unique. For instance, the palindrome 1001 will appear twice because it admits two factorizations:

    1001 = 11*91 = 13*77


Cheers,
raph
An excellent suggestion. Thank you very much. The only problem I have is your suggestion to use 'sol([A B B A] X Y)' . Bearing in mind I'm still learning about FD's, should I still bind this to my 'Root' identifier as before? When I try this all I get returned is nil!

Sorry, fixed it now. I used Root=sol(A B B A X Y). I got confused for a while there with the use of the square brackets.

Thanks again
Mark Richardson

_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to