RosettaCodeData/Task/Dinesmans-multiple-dwelling-problem/Picat/dinesmans-multiple-dwelling-problem-2.picat
2023-07-01 13:44:08 -04:00

18 lines
614 B
Text

%
% floors: 1: bottom .. 5: top floor
%
constraints([B,C,F,M,S]) =>
B != 5, % Baker not top floor
C != 1, % Cooper not bottom floor
F != 1, F != 5, % Fletcher not botton nor top floor
M > C, % Miller higher floor than Cooper
not adjacent(S, F), % Smith and Fletcher not adjacent
not adjacent(F, C). % Fletcher and Cooper not adjacent
adjacent(A,B) => abs(A-B) == 1.
dinesman2 =>
println(dinesman2),
foreach([B,C,F,M,S] in permutations(1..5), constraints([B,C,F,M,S]))
println([baker=B, cooper=C, fletcher=F, miller=M, smith=S])
end.