Hi,
I'm working through various tutorials on FD constraints and developed
the following program
++++++++++++++++++++++
%find all palindromic numbers of four digits that
%are the product of two digit numbers
declare
Palindrome
Results
proc {Palindrome Root}
A B C D E F G H %A-D are the palindrome digits
%E/F and G/H are the factors of the palindrome
in
Root=sol(a:A b:B c:C d:D e:E f:F g:G h:H)%set up the solution record
Root ::: 0#9 %all elements of Root are digits from 0 to 9
A \=:0 %palindrome can't begin with 0
A =: D %first digit must match last
B =: C %second digit must match third
(10* E + F) * (10 * G + H) =: A*1000 + B*100 + C*10 + D
%the product of the two digit numbers EF and GH must
%equal the number ABCD
{FD.distribute ff Root} %distribute Root using 'first-fail'
end
fun {Results L} %just to 'pretty-print' results
case L of H|T then
{VirtualString.toAtom {IntToString (10* H.e)+H.f}#" * "#
{IntToString (10*H.g)+H.h}#" = "#
{IntToString (1000*H.a)+(100*H.b)+(10*H.c)+H.d}}|{Results T}
else
nil
end
end
{Browse {Results{SearchAll Palindrome}}} %searchall solutions
%NB Display parameters under options in browser need changing
%to large browse limit to see all solutions
%118 in total
+++++++++++++++++++++++
the program works fine up to a point in that it produces all the correct
palindromes. However, half of them are duplicates.
Can anyone tell me how to approach avoiding symmetries in this case?
Any help would be great...
Mark Richardson
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users