/* Number the regions in Picat. From "The Inquisitive Problem Solver", problem 21, page 5. """ The three lines in the figure divide the circle into seven regions. Can you arrange the numbers 1 to 7 in these regions so that for each of the lines, the sums of the numbers on either side are all the same. """ This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import v3_utils. % import util. import cp. main => go. go ?=> N = 7, Lines = [ % side 1 side 2 [[1,5,6,7], [2,3,4]], [[1,2,6] , [3,4,5,7]], [[1,2,3,7], [4,5,6]] ], X = new_list(N), X :: 1..N, X[1] #= 1, % symmetry breaking all_different(X), foreach(I in 1..3) sum([X[J] : J in Lines[I,1]]) #= sum([X[J] : J in Lines[I,2]]) end, solve(X), println(X), fail, nl. go => true.