/* Place number puzzle in Picat. http://ai.uwaterloo.ca/~vanbeek/Courses/Slides/introduction.pdf """ Place numbers 1 through 8 on nodes - each number appears exactly once - no connected nodes have consecutive numbers 2 - 5 / | X | \ 1 - 3 - 6 - 8 \ | X | / 4 - 7 """ Compare with another approach: http://hakank.org/picat/place_number_puzzle2.pi Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => L = findall(X,place_number_puzzle(X)), writeln(L). place_number_puzzle(X) => N = 8, X = new_list(N), X :: 1..N, Graph ={{1,3}, {1,4}, {1,5}, {2,4}, {2,5}, {2,6}, {3,1}, {3,4}, {3,7}, {4,1}, {4,2}, {4,3}, {4,5}, {4,7}, {4,8}, {5,1}, {5,2}, {5,4}, {5,6}, {5,7}, {5,8}, {6,2}, {6,5}, {6,8}, {7,3}, {7,4}, {7,5}, {8,4}, {8,5}, {8,6}}, all_distinct(X), foreach(I in 1..Graph.length) abs(X[Graph[I,1]]-X[Graph[I,2]]) #> 1 end, % symmetry breaking X[1] #< X[N], solve(X).