/* Enigma puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles4.html, puzzle nr. 7 Description : Enigma Source : Herald Tribune circa November 1979 - courtesy of Dr Tito A. Ciriani """ 7. Enigma Assign all-different values to the letters in these words to make the equality true in English. ONE + ONE + TWO + TWO + THREE + ELEVEN = TWENTY (Unknown - Herald Tribune) """ This model was inspired by the XPress Mosel model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol4s7.html This is a CP model. Cf the MIP version: http://hakank.org/picat/enigma.pi This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. % import mip. % much slower main => go. go => All = findall(X,enigma(X)), foreach(Row in All) println(Row) end, nl. enigma(X) => Num = 10, X = new_list(Num), X :: 0..9, X = [O,N,E,T,W,H,R,L,V,Y], all_different(X), O #> 0, T #> 0, E #> 0, 100*O + 10*N + E + 100*O + 10*N + E + 100*T + 10*W + O + 100*T + 10*W + O + 10000*T + 1000*H + 100*R + 10*E + E + 100000*E + 10000*L + 1000*E + 100*V + 10*E + N #= 100000*T + 10000*W + 1000*E + 100*N + 10*T + Y, solve([ffc,split], X).