/* Triangular triangle puzzle in Picat. From Chris Smith's Math Newsletter #561 """ This newsletter has a triangular issue number ... so here's a triangle question (albeit ut features squares too). [Image were T is a triangle: T T T T T T T T T Represented by the positions 1 2 3 4 5 6 7 8 9 ] Your task is to fit the numbers 1 to 9 into the mini triangles so that the sum of the squares of the numbers along each side of the larger triangle is equal. """ There are 48 solutions without any symmetry breaking. With the symmetry breaking that the numbers in the left side should be increasing, we get these four solutions are shown (i.e. with some differences in the right and botton sides): 2 3 4 7 9 8 1 6 5 2 3 4 7 9 8 6 1 5 2 3 9 7 4 8 1 6 5 2 3 9 7 4 8 6 1 5 This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 9, X = new_list(N), X :: 1..9, all_different(X), L1 = [1,2,4,6], L2 = [1,3,5,9], L3 = [6,7,8,9], S1 #= sum([X[P]**2 : P in L1]), S2 #= sum([X[P]**2 : P in L2]), S3 #= sum([X[P]**2 : P in L3]), % Symmetry breaking. increasing([X[P] : P in L1]), S1 #= S2, S2 #= S3, solve(X), printf(" %d\n",X[1]), printf(" %d %d\n",X[2],X[3]), printf(" %d %d\n",X[4],X[5]), printf("%d %d %d %d\n",X[6],X[7],X[8],X[9]), nl, fail, nl. go => true.