/* Enigma Eighteen puzzle (#1496) in Picat. From http://www.f1compiler.com/samples/Enigma%201496.f1.html """ Eighteen Enigma 1496 Albert Haddad, New Scientist magazine, May 31, 2008 An eight digit "multiplicand" comprising of dots and letters is multiplied by 2 resulting in the product EIGHTEEN. Different letters stand for different digits, the same letter stands for the same digit, and a dot can be any digit. . . N I N E . . * 2 ---------------- = E I G H T E E N ---------------- What is the eight-digit product EIGHTEEN? """ EIGHTEEN Answer: 91637998 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 = [N,I,E,G,H,T,X1,X2,X3,X4], X :: 0..9, Nine = [X1,X2,N,I,N,E,X3,X4], Nine :: 0..9, EIGHTEEN = [E,I,G,H,T,E,E,N], EIGHTEEN :: 0..9, all_different([N,I,E,G,H,T]), E #>= 1, X1 #>= 1, 2*(10000000*X1 + 1000000*X2 + 100000*N + 10000*I + 1000*N + 100*E + 10*X3 + X4) #= ( 10000000*E + 1000000*I + 100000*G + 10000*H + 1000*T + 100*E + 10*E + N), Vars = X ++ Nine ++ EIGHTEEN, solve(Vars), println(x=X), println(nine=Nine), println(eighteen=EIGHTEEN), nl, fail, nl. go => true.