/* Enigma puzzle 1476: Portuguese squares in Picat. Problem formulation from http://www.f1compiler.com/samples/Enigma%201476.f1.html """ Zero, um, nove and cme are Portuguese for 0,1,9, and 100; so it is appropriate that I can make the folowing statement: ZERO,UM,NOVE and CEM are perfect squares. In this statement digits have been consistently replaced by capital letters, different letters being used for different digits. No number starts with a zero. Calculate the numerical value of square root of (ZERO*UM*NOVE*CEM) """ 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 = [Z,E,R,O,U,M,N,V,C], X :: 0..9, X1 :: 1..1000, X2 :: 1..10, X3 :: 1..1000, X4 :: 1..100, all_different(X), X1*X1 #= Z*1000+E*100+R*10+O, Z #>= 1, X2*X2 #= U*10+M, U #>= 1, X3*X3 #= N*1000+O*100+V*10+E, N #>= 1, X4*X4 #= C*100+E*10+M, C #>= 1, SquareRoot #= X1*X2*X3*X4, Vars = X ++ [X1,X2,X3,X4,SquareRoot], solve(Vars), println(x=X), println([x1,x2,x3,x4]=[X1,X2,X3,X4]), println(squareRoot=SquareRoot), nl, fail, nl. go => true.