/* The hexagon in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 120. The hexagon Enter integers from 1 through 19 in the spots of the hexagon so that each row of three (on the rim, and outward from the centre) adds to 22. Rearrange to add to 23. (puzzle 327 from Kordemsky (1992)) (Fig.11.16) """ Without any symmetry breaking: * sum = 22: 48 solutions * sum = 23: 24 solutions With summetry breaking X[1] = 1: * sum = 22: 8 solutions [1,9,12,18,19,8,6,3,17,2,16,4,14,15,13,11,5,10,7] [1,13,8,18,19,12,10,3,17,2,16,4,14,15,9,7,5,6,11] [1,14,7,18,19,13,6,3,17,2,11,9,15,16,12,5,4,10,8] [1,18,3,9,19,17,14,12,8,2,15,5,6,16,13,10,4,11,7] [1,18,3,13,19,17,14,8,12,2,15,5,10,16,9,6,4,7,11] [1,18,3,14,19,17,15,7,13,2,16,4,6,11,12,10,9,5,8] [1,18,3,19,17,15,9,2,16,4,8,10,14,12,13,7,6,11,5] [1,19,2,18,17,16,14,3,15,4,12,6,9,8,13,11,10,7,5] * sum = 23: 4 solutions [1,12,10,19,16,7,5,3,14,6,9,8,18,15,13,11,2,17,4] [1,18,4,19,16,13,17,3,14,6,15,2,12,9,7,11,8,5,10] [1,19,3,12,16,14,18,10,7,6,15,2,5,9,13,17,8,11,4] [1,19,3,18,16,14,12,4,13,6,9,8,17,15,7,5,2,11,10] 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 => member(Sum,[22,23]), nl, println(sum=Sum), N = 19, X = new_list(N), X :: 1..N, all_different(X), Ts = [[1,2,3], [1,4,8], [1,5,10], [3,6,10], [3,7,12], [8,9,10], [8,13,17], [10,11,12], [10,14,17], [10,15,19], [12,16,19], [17,18,19]], foreach(T in Ts) sum([X[I] : I in T]) #= Sum end, % Symmetry breaking X[1] #= 1, solve(X), println(x=X), fail, nl.