/* Enigma #1104 (Odd and even squares) in Picat. From https://enigmaticcode.wordpress.com/2017/07/31/enigma-1104-odd-and-even-squares/ """ From New Scientist #2260, 14th October 2000 In the following statement digits have been consistently replaced by capital letters, different letters being used for different digits: ONE and NINE are odd perfect squares, FOUR is an even perfect square. Find the numerical value of the square root of (NINE × FOUR × ONE). """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => time2(go). go => L = [O,N,E,I,F,U,R], L :: 0..9, all_distinct(L), ONE :: 100..999, ONE #= 100*O + N*10 + E, NINE :: 1000..9999, NINE #= 1000*N + 100*I + N*10 + E, FOUR :: 1000..9999, FOUR #= 1000*F + 100*O + U*10 + R, perfect_square(ONE), perfect_square(NINE), perfect_square(FOUR), ONE mod 2 #= 1, NINE mod 2 #= 1, FOUR mod 2 #= 0, solve([ff,split],L), println(round(sqrt(NINE*FOUR*ONE))), fail, nl. perfect_square(X) => % restrict the domain of Y fd_min_max(X, Min, Max), Y :: ceiling(sqrt(Min))..ceiling(sqrt(Max)), Y*Y #= X. % Not needed since we can calculate the square root by round(sqrt(...)). % square_root(X,Y) => % % restrict the domain of Y % fd_min_max(X, Min, Max), % Y :: ceiling(sqrt(Min))..ceiling(sqrt(Max)), % Y*Y #= X.