/* Sequence puzzle in Picat. From the ECLiPSe book "Constraint Logic Programming using ECLiPSe", page 109. Exercise 6.2 """ Find a permutation of numbers 1,..,10 such that - 6 is put on 7th place - each number starting from the second one is either bigger by 3 or smaller by 2 than its predecessor. """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => N = 10, X = new_list(N), X :: 1..N, all_different(X), X[6] #= 7, foreach(I in 2..N) X[I] - X[I-1] #= 3 #\/ X[I] - X[I-1] #= -2 end, solve(X), println(X), fail, nl.