/* Five floors problem in Picat. From Alexey Radul & Gerald Jay Sussman: "The Art of Propagator", page 34 """ Baker, Cooper, Fletcher, Miller, and Smith live on the first five floors of this apartment house. Baker does not live on the fifth floor. Cooper does not live on the first floor. Fletcher does not live on either the fifth or the first floor. Miller lives on a higher floor than does Cooper. Smith does not live on a floor adjacent to Fletcher'. Fletcher does not live on a floor adjacent to Cooper's. """ 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 = 5, X = [Baker, Cooper, Fletcher, Miller, Smith], X :: 1..N, all_different(X), % Baker does not live on the fifth floor. Baker #!= 5, % Cooper does not live on the first floor. Cooper #!= 1, % Fletcher does not live on either the fifth or the first floor. Fletcher #!= 5, Fletcher #!= 1, % Miller lives on a higher floor than does Cooper. Miller #> Cooper, % Smith does not live on a floor adjacent to Fletcher'. abs(Smith-Fletcher) #> 1, % Fletcher does not live on a floor adjacent to Cooper's. abs(Fletcher-Cooper) #> 1, solve(X), println(X), fail, nl. go => true.