/* Crystal Maze problem in Picat. From http://phys.org/news/2015-11-problems-ai-future-british-gameshow.html """ On the wall was written a clue: "No consecutive letters in adjacent circles". The letters A to H were printed on circular plates which could be fitted onto each circle. ? ? ? A H ? ? ? [ Represented with numbers, the cell are: 2 3 1 4 5 6 7 8 And the connections: 1,2, 1,4, 1,7, 2,3, 2,4, 2,5, 3,5, 3,6, 4,5, 4,7, 4,8, 5,6, 5,7, 5,8, 6,8, 7,8 ] """ There are four solutions: D F G A H B C E ---------- E B G A H D C F ---------- C E G A H B D F ---------- D B G A H F E C ---------- This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> L = [A,_B,_C,_D,_E,_F,_G,H], N = L.len, L = 1..N, S = ["A","B","C","D","E","F","G","H"], Connections = [ [1,2], [1,4], [1,7], [2,3], [2,4], [2,5], [3,5], [3,6], [4,5], [4,7], [4,8], [5,6], [5,7], [5,8], [6,8], [7,8]], NumConnections = Connections.len, Hints = [ 0, % 1 0, % 2 0, % 3 A, % 4 H, % 5 0, % 6 0, % 7 0 % 8 ], X = new_list(N), X :: 1..N, all_different(X), foreach(I in 1..NumConnections) abs(X[Connections[I,1]] - X[Connections[I,2]]) #> 1 end, foreach(I in 1..N) Hints[I] #> 0 #=> X[I] #= Hints[I] end, solve(X), println(x=X), printf("\n"), printf(" %s %s\n",S[X[2]],S[X[3]]), printf(" %s %s %s %s\n", S[X[1]],S[X[4]],S[X[5]],S[X[6]]), printf(" %s %s\n", S[X[7]],S[X[8]]), printf("\n"), fail, nl. go => true.