/* Nine-digit arrangement in Picat. Martin Garder. April 1972. Arrange the digits 1..9 in two multiplications which give the same product, ABC FG * DE * HI ----- ---- ???? ???? There are 11 solutions to this equation. The maximum product is 7448 which has the following solution: 532 * 14 ----- 7448 76 * 98 ----- 7448 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 = [A,B,C,D,E,F,G,H,I], X :: 1..9, all_different(X), S #= (100*A + 10*B + C) * (10*D + E), S #= (10*F + G) * (10*H + I), (10*F + G) #<= (10*H + I), % symmetry breaking % S #= 7448, % only the optimal solutions solve(X), % println(x=X),a printf(" %d%d%d\n", A,B,C), printf("* %d%d\n", D,E), print("-----\n"), printf(" %d\n",S), nl, printf(" %d%d\n", F,G), printf("* %d%d\n", H,I), print("-----\n"), printf(" %d\n",S), println("-------------"), nl,nl, fail, nl. go => true. % % Only the optimal solution (S = 7448) % go2 ?=> X = [A,B,C,D,E,F,G,H,I], X :: 1..9, all_different(X), S #= (100*A + 10*B + C) * (10*D + E), S #= (10*F + G) * (10*H + I), (10*F + G) #<= (10*H + I), % symmetry breaking S #= 7448, % the optimal solutions solve(X), % println(x=X),a printf(" %d%d%d\n", A,B,C), printf("* %d%d\n", D,E), print("-----\n"), printf(" %d\n",S), nl, printf(" %d%d\n", F,G), printf("* %d%d\n", H,I), print("-----\n"), printf(" %d\n",S), println("-------------"), nl,nl, fail, nl. go2 => true.