/* Three digit puzzle in Picat. http://www.delphiforfun.org/Programs/brute_force.htm "What 3 digit number together with it's square contains all 10 digits?" Solutions (allows A and D to be 0) N = 854, N^2 = (0)729316 N = 567 N^2 = (0)321489 Note that D must be 0. This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => X = [A,B,C,D,E,F,G,H,I,J], X :: 0..9, N :: 123..978, all_different(X), N #= 100*A + 10*B + C, % the 3 digit number N*N #= 1000000*D + 100000*E + 10000*F + 1000*G + 100*H + 10*I + J, % the square A #> 0, % D #> 0, % no solution if D > 0 println(X), solve(X ++ [N]), println(X), println(n=N), println('n**2'=(N**2)), nl, fail, nl.