/* From 1 through 19 in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 112. From 1 through 19 Write the numbers from 1 through 19 in the circles so that the numbers in every 3 cir- cles on a straight line sum up to 30. (puzzle 34 from Kordemsky (1992)) (Fig. 11.7) """ Here we encode the mid circle as X[19]. There is a huge number of solutions for this puzzle, for example [1,2,3,4,5,6,7,8,9,19,18,17,16,15,14,13,12,11,10] [1,2,3,4,5,6,7,8,11,19,18,17,16,15,14,13,12,9,10] [1,2,3,4,5,6,7,9,8,19,18,17,16,15,14,13,11,12,10] ... With the simple symmetry that X[1] == 1, there are 10321920 solutions. All mid values (X[19]) are 10. With the symmetry breaking increasing(X[1..9]) there are 256 solutions: [1,2,3,4,5,6,7,8,9,19,18,17,16,15,14,13,12,11,10] [1,2,3,4,5,6,7,8,11,19,18,17,16,15,14,13,12,9,10] [1,2,3,4,5,6,7,9,12,19,18,17,16,15,14,13,11,8,10] ... [1,8,9,13,14,15,16,17,18,19,12,11,7,6,5,4,3,2,10] [1,8,11,13,14,15,16,17,18,19,12,9,7,6,5,4,3,2,10] [1,9,12,13,14,15,16,17,18,19,11,8,7,6,5,4,3,2,10] [1,11,12,13,14,15,16,17,18,19,9,8,7,6,5,4,3,2,10] Kordemsky's single solution is this nice symmetric solution: [1,2,3,4,5,6,7,8,9,19,18,17,16,15,14,13,12,11,10] This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import sat. main => go. go => N = 19, Sum = 30, X = new_list(N), X :: 1..N, all_different(X), Mid #= X[19], % Mid #!= 10, % Checking other mid values: There are none other mi value foreach(I in 1..9) X[I] + Mid + X[I+9] #= Sum end, % Symmetry breaking X[1] #= 1, increasing(X[1..9]), solve(X), println(x=X), fail, nl.