Created
June 1, 2021 08:20
-
-
Save Pagliacii/b52ed6d79b8e1a3e0373c72175868df4 to your computer and use it in GitHub Desktop.
The following puzzle takes from Dinesman's Superior Mathematical Puzzles in 1968.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Where does everyone live? | |
* | |
* 1. Baker, Cooper, Fletcher, Miller, and Smith live on different floors of an apartment house that contains only five floors. | |
* 2. Baker does not live on the top floor. | |
* 3. Cooper does not live on the bottom floor. | |
* 4. Fletcher does not live on either the top or the bottom floor. | |
* 5. Miller lives on a higher floor than does Cooper. | |
* 6. Smith does not live on a floor adjacent to Fletcher's. | |
* 7. Fletcher does not live on a floor adjacent to Cooper's. | |
*/ | |
higher(A, B, Ls) :- | |
nth0(M, Ls, A), | |
nth0(N, Ls, B), | |
M > N. | |
adjacent(A, B, Ls) :- | |
append(_, [A, B | _], Ls); | |
append(_, [B, A | _], Ls). | |
floors(Fs) :- | |
length(Fs, 5), member(baker, Fs), member(cooper, Fs), member(fletcher, Fs), member(miller, Fs), member(smith, Fs), % 1 | |
\+ nth0(4, Fs, baker), % 2 | |
\+ nth0(0, Fs, cooper), % 3 | |
\+ nth0(4, Fs, fletcher), \+ nth0(0, Fs, fletcher), % 4 | |
higher(miller, cooper, Fs), % 5 | |
\+ adjacent(smith, fletcher, Fs), % 6 | |
\+ adjacent(fletcher, cooper, Fs). % 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answer