/* Arithmetic Ring problem in Picat. From "Star problems" http://mathschallenge.net/problems/pdfs/mathschallenge_1_star.pdf page 6, """ Problem The digits 1, 2, 3, 4, 5, 6, 7 and 8 are placed in the ring below. 1 5 3 8 _ 7 4 6 2 With the exception of 6 and 7, no two adjacent numbers are consecutive. Show how it is possible to arrange the digits 1 to 8 in the ring so that no two adjacent numbers are consecutive. """ Note: I interpret this as 6 and 7 _must_ be adjacent. 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 ?=> N = 8, X = new_list(N), X :: 1..N, all_different(X), % no consecutive number (except 6 and 7) can be adjacent foreach(I in 2..N) check(X[I-1], X[I]) end, % around the corner check(X[N], X[1]), % however, 6 and 7 must be adjacent % (it cannot be "around the corner" since x[1] = 1) % sum([(X[I] #= 6 #/\ X[I+1] #= 7) #\/ % (X[I] #= 7 #/\ X[I+1] #= 6) : I in 2..N-1]) #> 0, % simpler approach element(Pos6,X,6), element(Pos7,X,7), abs(Pos6-Pos7) #= 1, % symmetry breaking X[1] #= 1, solve(X), println(X), fail, nl. go => true. check(A, B) => ( #~(A #= 6 #/\ B #= 7) #/\ #~(A #= 7 #/\ B #= 6) ) #=> abs(A-B) #> 1.