Dinesman's multiple-dwelling problem: Difference between revisions

Content added Content deleted
(→‎{{header|Picat}}: Moved into subsections, added {{out}})
Line 2,728: Line 2,728:


=={{header|Picat}}==
=={{header|Picat}}==
===Constraint modelling===
First a constraint modelling version (using Picat's cp module), then a version using permutations.

<lang picat>import util.
<lang picat>import util.
import cp.
import cp.


go =>
dinesman_cp,
dinesman2,
nl.


% CP approach
dinesman_cp =>
dinesman_cp =>
println(dinesman_cp),
println(dinesman_cp),
Line 2,769: Line 2,761:
solve(X),
solve(X),


println([baker=Baker, cooper=Cooper, fletcher=Fletcher, miller=Miller, smith=Smith]).
println([baker=Baker, cooper=Cooper, fletcher=Fletcher, miller=Miller, smith=Smith]).</lang>


{{out}}
<pre>[baker = 3,cooper = 2,fletcher = 4,miller = 5,smith = 1]</pre>


===Using permutations===
%
<lang Picat>%
% The constraints (non CP approach)
%
% floors: 1: bottom .. 5: top floor
% floors: 1: bottom .. 5: top floor
%
%
Line 2,787: Line 2,780:
adjacent(A,B) => abs(A-B) == 1.
adjacent(A,B) => abs(A-B) == 1.


% Non-CP approach, using permutations
dinesman2 =>
dinesman2 =>
println(dinesman2),
println(dinesman2),
Line 2,795: Line 2,787:
</lang>
</lang>


{{out}}
Output:
<pre>[baker = 3,cooper = 2,fletcher = 4,miller = 5,smith = 1]</pre>
<pre>
dinesman_cp
[baker = 3,cooper = 2,fletcher = 4,miller = 5,smith = 1]
dinesman1
[baker = 3,cooper = 2,fletcher = 4,miller = 5,smith = 1]
</pre>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==