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}} |
|||
⚫ | |||
===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> |
|||
dinesman_cp |
|||
⚫ | |||
dinesman1 |
|||
⚫ | |||
</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |