/* Langford problem in Picat. Ported from the Prolog code in H. Coelho and J.C. Cotta. "Prolog by Example" (Springer-Verlag, Berlin, 1988), page 193. Where the problem is to arrange three 1's, three 2's, ..., three 9's in sequence so that for all i 2 1 ; 9] there are exactly i numbers between successive occurrences of i. Compare with the Langford problem: http://hakank.org/picat/langford_generalized.pi This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => go. go ?=> question(Ss), println(Ss), fail, nl. go => true. sublist(Ys,XsYsZs) => append(Xs,YsZs,XsYsZs), append(Ys,Zs,YsZs). sequence(S) => S = [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_]. question(Ss) => sequence(Ss), sublist([1,_,1,_,1],Ss), sublist([2,_,_,2,_,_,2],Ss), sublist([3,_,_,_,3,_,_,_,3],Ss), sublist([4,_,_,_,_,4,_,_,_,_,4],Ss), sublist([5,_,_,_,_,_,5,_,_,_,_,_,5],Ss), sublist([6,_,_,_,_,_,_,6,_,_,_,_,_,_,6],Ss), sublist([7,_,_,_,_,_,_,_,7,_,_,_,_,_,_,_,7],Ss), sublist([8,_,_,_,_,_,_,_,_,8,_,_,_,_,_,_,_,_,8],Ss), sublist([9,_,_,_,_,_,_,_,_,_,9,_,_,_,_,_,_,_,_,_,9],Ss), % hakank: added symmetry breaking Ss[1] < Ss[27].