/* Eight numbers in a cube in Picat. From Chris Smith's Math Newsletter #554 """ Put eight different numbers (pick integers from 0 to 12) at the corners of the cube so that the difference between pairs of corners are 1,2,3,4,5,6,7,8,9,10,11,12 """ 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. /* It's 6 solutions with the two symmetry breaking constraints: X[1] #= 0, Diffs[1] #= 1, x = [0,1,11,3,12,5,2,8] diffs = [1,11,12,2,4,8,9,5,7,10,3,6] x = [0,1,11,7,12,4,2,9] diffs = [1,11,12,6,3,4,9,2,8,10,5,7] x = [0,1,11,8,12,6,2,10] diffs = [1,11,12,7,5,3,9,2,6,10,4,8] x = [0,1,12,4,11,7,2,9] diffs = [1,12,11,3,6,8,10,5,4,9,2,7] x = [0,1,12,5,11,3,2,8] diffs = [1,12,11,4,2,7,10,3,8,9,5,6] x = [0,1,12,6,11,8,2,10] diffs = [1,12,11,5,7,6,10,4,3,9,2,8] Without symmetry breaking it's 2592 solutions. */ go ?=> N = 8, X = new_list(N), X :: 0..12, all_different(X), Connections = [ [1,2],[1,3],[1,5], [2,4],[2,6], [3,4],[3,7], [4,8], [5,6],[5,7], [6,8], [7,8] ], Diffs = [], foreach([I,J] in Connections) D #= abs(X[I]-X[J]), Diffs := Diffs ++ [D] end, foreach(I in 1..12) sum([Diffs[J] #= I : J in 1..Diffs.len]) #>= 1 end, all_different(Diffs), % Symmetry breaking X[1] #= 0, Diffs[1] #= 1, Vars = X ++ Diffs, solve(Vars), println(x=X), println(diffs=Diffs), nl, fail, nl. go => true.