Dinesman's multiple-dwelling problem: Difference between revisions

Content deleted Content added
Hansoft (talk | contribs)
Loren (talk | contribs)
Add XPL0 (3rd attempt)
Line 1,385: Line 1,385:
Sample output:
Sample output:
<pre>From bottom to top: Smith Cooper Baker Fletcher Miller</pre>
<pre>From bottom to top: Smith Cooper Baker Fletcher Miller</pre>

=={{header|XPL0}}==
<lang XPL0>include c:\cxpl\codes;
int B, C, F, M, S;
for B:= 1 to 4 do \Baker does not live on top (5th) floor
for C:= 2 to 5 do \Cooper does not live on bottom floor
if C#B then \Cooper & Baker live on different floors
for F:= 2 to 4 do \Fletcher doesn't live on top or bottom
if F#B & F#C & F#C-1 & F#C+1 then \ and she's not adjacent to Cooper
for M:= 1 to 5 do
if M#F & M#B & M>C then \Miller lives above Cooper
for S:= 1 to 5 do \Smith is not adjacent to Fletcher
if S#M & S#F & S#C & S#B & S#F-1 & S#F+1 then \show
[Text(0, "Baker "); IntOut(0, B); CrLf(0); \all
Text(0, "Cooper "); IntOut(0, C); CrLf(0); \possible
Text(0, "Fletcher "); IntOut(0, F); CrLf(0); \solutions
Text(0, "Miller "); IntOut(0, M); CrLf(0);
Text(0, "Smith "); IntOut(0, S); CrLf(0);
]</lang>

Output:
<pre>
Baker 3
Cooper 2
Fletcher 4
Miller 5
Smith 1
</pre>