/* Order the numbers in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 115. Order the numbers The diagram shows 1 through 10 (in order) at the tips of five diameters. Only once does the sum of two adjacent numbers equal the sum of the opposite two numbers: 10 + 1 = 5 + 6. Elsewhere, for example, 1 + 2 = 6 + 7 or 2 + 3 = 7 + 8. Rearrange the numbers so that all such sums are equal. You can expect more than one solution to this problem. How many basic solutions are there? How many variants (not including simple rotations of variants)? (puzzle 51 from Kordemsky (1992)) (Fig. 11.9) """ 10 1 9 2 8 3 7 4 6 5 Number of solutions * No symmetry breaking : 480 * X[1] #= 1 : 48 * X[1] #= 1 and X[2] #= 4 : 4 * increasing(X[1..5]) : 2 * X[1] #= 1 and increasing(X[1..5]) : 1 Here are the single solution with X[1] #= 1 and increasing(X[1..5]): x = [1,4,5,8,9,2,3,6,7,10] 10 1 7 4 6 5 3 8 2 9 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 => N = 10, X = new_list(N), X :: 1..N, all_different(X), foreach(I in 0..N-5-1) I1 = 1+(I mod N), I2 = 1+((I+5) mod N), J1 = 1+((I+1) mod N), J2 = 1+((I+1+5) mod N), X[I1] + X[J1] #= X[I2] + X[J2] end, % symmetry breaking X[1] #= 1, % X[2] #= 4, increasing(X[1..5]), solve(X), println(x=X), nl, printf(" %2d %2d\n", X[10],X[1]), nl, printf(" %2d %2d\n", X[9],X[2]), nl, printf(" %2d %2d\n", X[8],X[3]), nl, printf(" %2d %2d\n", X[7],X[4]), nl, printf(" %2d %2d\n",X[6],X[5]), nl, fail, nl.