Last active
June 2, 2021 07:26
-
-
Save Pagliacii/330a191818dbb00b018996905a74c445 to your computer and use it in GitHub Desktop.
Solve the following “Liars” puzzle from The Sphinx Problem Book by Phillips Hubert in 1934.
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
/* What in fact was the order in which the five girls were placed? | |
* | |
* Five schoolgirls sat for an examination. Their parents--so they thought--showed an undue degree of interest | |
* in the result. They therefore agreed that, in writing home about the examination, each girl should make one | |
* true statement and one untrue one. The following are the relevant passages from their letters: | |
* | |
* 1. Betty: "Kitty was second in the examination. I was only third." | |
* 2. Ethel: "You'll be glad to hear that I was on top. Joan was 2nd." | |
* 3. Joan: "I was third, and poor old Ethel was bottom." | |
* 4. Kitty: I came out second. Mary was only fourth." | |
* 5. Mary: "I was fourth. Top place was taken by Betty." | |
*/ | |
xor(A, B) :- | |
A, not(B); | |
B, not(A). | |
liars(Ls) :- | |
length(Ls, 5), | |
member(betty, Ls), member(ethel, Ls), member(joan, Ls), member(kitty, Ls), member(mary, Ls), | |
xor(nth1(2, Ls, kitty), nth1(3, Ls, betty)), | |
xor(nth1(1, Ls, ethel), nth1(2, Ls, joan)), | |
xor(nth1(3, Ls, joan), nth1(5, Ls, ethel)), | |
xor(nth1(2, Ls, kitty), nth1(4, Ls, mary)), | |
xor(nth1(4, Ls, mary), nth1(1, Ls, betty)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answer