/* Enigma problem 1568 (Odd puzzle) in Picat. From New Scientist http://www.newscientist.com/article/mg20427311.100-enigma-number-1568.html """ 21 October 2009 by Albert Haddad Odd puzzle In this multiplication sum the digits have been replaced by letters and dots. Different letters stand for different digits, the same letter stands for the same digit, each dot can be any digit, and leading digits cannot be zero. [ . . . | num1 * . . . | num2 ------- . . . | num3 . . . | num4 O D D | ODD --------- P U Z Z L E | PUZZLE ] What is the six-figure odd PUZZLE? """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> X = [O,D,P,U,Z,L,E], X :: 0..9, Nums = [Num1,Num2,Num3,Num4,ODD], Nums :: 100..999, PUZZLE :: 100000..999999, all_different(X), ODD #= 100*O + 10*D + D, PUZZLE #= 100000*P + 10000*U + 1000*Z + 100*Z + 10*L + E, Num1 * Num2 #= Num3 + Num4*10 + ODD*100, PUZZLE #= Num1 * Num2, PUZZLE mod 2 #= 1, % PUZZLE is odd % And then code the "long multiplication" Num1 * (Num2 mod 10) #= Num3, Num1 * ((Num2 div 10) mod 10) #= Num4, Num1 * (Num2 div 100) #= ODD, Vars = X ++ Nums, solve([ff,split],Vars), println(x=X), println(puzzle=PUZZLE), nl, fail, nl. go => true.