# Self Referential Puzzle - medium 2

Does anyone have a solution for this puzzle?

I keep getting contradictions. If anyone knows the answer, I would be happy to see what logic failures I am making.

1. The first question whose answer is D is the question
A.  8
B.  7
C.  6
D.  5
E.  4

A.  3 and 4
B.  4 and 5
C.  5 and 6
D.  6 and 7
E.  7 and 8

3. The number of questions with the answer E is
A.  1
B.  2
C.  3
D.  4
E.  5

4. The number of questions with the answer A is
A.  1
B.  2
C.  3
D.  4
E.  5

5. The number of questions with the answer A equals the number of questions with the answer
A.  A
B.  B
C.  C
D.  D
E.  none of the above

6. The last question whose answer is B is the question
A.  5
B.  6
C.  7
D.  8
E.  9

7. Alphabetically, the answer to this question and the answer to the following question are
A.  4 apart
B.  3 apart
C.  2 apart
D.  1 apart
E.  the same

8. The answer to this question is the same as the answer to the question
A.  1
B.  2
C.  3
D.  4
E.  5

9. The number of questions whose answers are consonants
A.  3
B.  4
C.  5
D.  6
E.  7

10. The answer to this question is
A.  A
B.  B
C.  C
D.  D
E.  E


(What follows is my actual reasoning process, recorded as it went along. I haven't attempted to optimize it. I've spoilered basically none of it, because spoilering lots of paragraphs is tedious and this stuff is extremely easy to skip over without reading.)

From Q7, we see that Q8 has to be one of A,C,E. That means that we have one of 1A, 3C, 5E. It can't be the first of these because then we'd have to have 8D. It can't be the last because 5E says inter alia that the number of As doesn't equal the number of As. Therefore it's 8C and 3C, and from 8C we infer 7D. 3C tells us that there are three Es in total.

We can't have 1A because we have 7D. We can't have 1D because all the options on Q1 are 4 or later. This also means we don't have 2D (or 3D, but we already knew that.)

We can't have 10B because of Q6.

If 1E then 4D implying that there are four As as well as three Es. But we then have E?CD??DC?? and those five gaps need to supply four A and two E, contradiction. So not 1E, leaving B or C for Q1. That means no Ds before Q6. (And it means either Q6 or Q7 is D, but we already knew 7D.) Oh, and actually Q6 can't be D because that would mean 8B, but we have 8C. (Neither, while we're here, can it be C because we have 7D.) So in fact 1B.

We now have four consonants, so we can rule out 9A. We also have three Es, so there are at most three As, so we can rule out 4D (which was already impossible) and 4E (which wasn't). Those three Es, combined with the fact that (per Q4) there's at least one A, also rule out 9E.

At this point the only questions whose answer can be E are 2,6,10, and we have to have three Es, so there they are. This leaves only Q4 and Q5 that could be A, which means there are at most two As, so Q4 is A or B.

6E means that the last B is Q9. In particular, 9B. (And not 10B, but we already knew that.)

If 5B then #A=#B but #B>=3 and at this point we only have room for one A. So not 5B. If 5C then #A=#C but #C>=3 and this is impossible for the same reason. We have already ruled out 5D and 5E; so 5A.

At this point, we have a problem. If 4A then there must be just one A, but we have both 4A and 5A. If 4B then there must be two As, but we have only 5A.

So unless I've made a mistake

it is not possible to answer all these questions correctly.

It would be worth

writing a program to check this -- $5^{10}$ is pretty small. But I don't have time right now.

• I have a feeling a solution does exist although I am having a hard time finding one - just an assumption because it came from an online source that does these a lot. – n_plum Apr 19 '17 at 17:56
• I've asked someone to write such a program at code-golf SE – usernameiwantedwasalreadytaken Apr 19 '17 at 18:50
• I had the same problem - I keep coming up with contradictions. I can only assume I am interpreting one of the questions incorrectly. – Trenin Apr 19 '17 at 18:58
• I wrote a program to test this. Unless I miscoded it or misinterpreted it, there are no valid responses. I came over here from code-golf but didn't feel like golfing the solution as much as finding an answer. Feel free to check my work pastebin.com/TzzGmFvB (Also if anyone knows why it's swallowing some leading spaces let me know) – PunPun1000 Apr 19 '17 at 19:46

I tried to solve it manually:

Based on Q1 - There must be at least one D from Q4 to Q8.

Q2 - From Q3 to Q8, there are two consecutive questions with the same answer.

Q3 - There can be 1 to 5 Es.

Q4 - There can be 1 to 5 As.

Q5 - A by definition. Also, the number of As is different from those of the other letters (except for maybe E).

Q6 - There must be at least one B from Q5 to Q9.

Q7, 8 - Q8 can be A, C or E. Q2 and Q4's answers are different from Q8's.

Now, on one hand, Q6's answer can only be B due to the lack of other options for the B mentioned. On the other hand, that doesn't allow for more than one E.

Going through logically and manually (listed out below) I came to contradictions.

Furthermore, below that, I present two near-solutions for which the linked web-page states each have only one incorrect answer.

Steps X1 - X22 should each be small enough steps to follow, and X23 gives two resulting contradictions, either of which should also be quite easy to see. Along the way I update a list of what we know - ten separate lists of five items each (much like the marks one can add to the linked webpage) - these are ordered left to right by question and each is ordered left to right by alphabetical answer and all are initially question marks, the become x when ruled out and their letter when ruled in.

X1.
Q5: The number of questions with the answer A equals the number of questions with the answer
Must be A. A - it is a tautology)
????? ????? ????? ????? Axxxx ????? ????? ????? ????? ?????

X2.
Q4: The number of questions with the answer A is
cannot be A.1 (it would now create a second A)
????? ????? ????? x???? Axxxx ????? ????? ????? ????? ?????

X3.
Cannot be B. 4&5 (Q5 is A but Q4 cannot be A by X2)
????? ?x??? ????? x???? Axxxx ????? ????? ????? ????? ?????

X4.
Q6: The last question whose answer is B is the question
cannot be A.5 (5 is already A by X1)
????? ?x??? ????? x???? Axxxx x???? ????? ????? ????? ?????

X5
Cannot be C. 5&6 (Q5 is A but Q6 cannot be A by X4)
????? ?xx?? ????? x???? Axxxx x???? ????? ????? ????? ?????

X6.
Q8: The answer to this question is the same as the answer to the question
Cannot be B.2 (Q2 cannot be B from B3)
????? ?xx?? ????? x???? Axxxx x???? ????? ?x??? ????? ?????

X7.
Q8: The answer to this question is the same as the answer to the question
Cannot be E.5 (Q5 is A from X1)
????? ?xx?? ????? x???? Axxxx x???? ????? ?x??x ????? ?????

X8.
Q8: The answer to this question is the same as the answer to the question
Cannot be A.1 (If Q1 were then the first question to be D would be 8, making this D - contradiction)
????? ?xx?? ????? x???? Axxxx x???? ????? xx??x ????? ?????

X9.
Q8: The answer to this question is the same as the answer to the question
Cannot be D.4 (if it were then all answers to question 7 would contradict it)
????? ?xx?? ????? x???? Axxxx x???? ????? xx?xx ????? ?????

X10.
Q8: The answer to this question is the same as the answer to the question
Must be C.3 (only option reamining)
????? ?xx?? ????? x???? Axxxx x???? ????? xxCxx ????? ?????

X11.
Q7: Alphabetically, the answer to this question and the answer to the following question are
Must be D.1 apart (as per X9.)
????? ?xx?? ????? x???? Axxxx x???? xxxDx xxCxx ????? ?????

X12.
Q3: The number of questions with the answer E is
Must be C.3 (direct implication of Q8 being C by X9)
????? ?xx?? xxCxx x???? Axxxx x???? xxxDx xxCxx ????? ?????

X13.
Q6: The last question whose answer is B is the question
Cannot be C.7 or D.8 (since Q7 and Q8 are D, not B, by X11 and X10 respectively)
????? ?xx?? xxCxx x???? Axxxx x?xx? xxxDx xxCxx ????? ?????

X14.
Q10: The answer to this question is
Cannot be B.B (it would make all answers to Q6 invalid options)
????? ?xx?? xxCxx x???? Axxxx x?xx? xxxDx xxCxx ????? ?x???

X15.
Q4: The number of questions with the answer A is
Cannot be E.5 (One answer is A, 6 quesions remain unanswered 3 of which must be E by Q3 and X12, 6-3+1 = 4, 5>4)
????? ?xx?? xxCxx x???x Axxxx x?xx? xxxDx xxCxx ????? ?x???

X16.
Q4: The number of questions with the answer A is
Cannot be D.4 (Following on from X15 but knowing Q4 can no longer be A or E, 5-3+1 = 3, 4>3)
????? ?xx?? xxCxx x??xx Axxxx x?xx? xxxDx xxCxx ????? ?x???

X17.
Q1: The first question whose answer is D is the question
Cannot be A.8 (since Q7 is D by X11)
x???? ?xx?? xxCxx x??xx Axxxx x?xx? xxxDx xxCxx ????? ?x???

X18.
Q1: The first question whose answer is D is the question
Cannot be E.4 (since Q4 is not D by X16)
x???x ?xx?? xxCxx x??xx Axxxx x?xx? xxxDx xxCxx ????? ?x???

X19.
Cannot be E.7&8 (Q7 is D and Q8 is C by X11 and X10 respectively)
x???x ?xx?x xxCxx x??xx Axxxx x?xx? xxxDx xxCxx ????? ?x???

X20.
Cannot be D.6&7 (Q6 is not D by X13 while Q7 is D by X11)
x???x ?xxxx xxCxx x??xx Axxxx x?xx? xxxDx xxCxx ????? ?x???

X21.
Must be A.3&4 (only option reamining)
x???x Axxxx xxCxx x??xx Axxxx x?xx? xxxDx xxCxx ????? ?x???

X22.
Q4: The number of questions with the answer A is
Must be C.3 (direct implication of Q2 beint A.3&4 by X21)
x???x Axxxx xxCxx xxCxx Axxxx x?xx? xxxDx xxCxx ????? ?x???

X23.
There are now three unanswered questions which have E available (Q6, Q9, & Q10) and
Q3: The number of questions with the answer E is
hence they must all be E, however they cannot be since Q6 being E implies Q9 is D.
(There is also a contradiction with the fact that if they were all E, a third A for Q4 would not be available)

If we ignore the implications of question 5 then the single solution would be:

Answer: 1 2 3 4 5 6 7 8 9 10
-Q5: B A B B E B D E D A


This is also much like treating Q5 as if the answer were E. None of the above, since there are 2 As, 2 Ds and 2 Es - hence the options A and D are not valid, hence "none of the above". I was half expecting this to come up all green.

If we ignore the implications instead of question 8 then the single solution would be:

Answer: 1 2 3 4 5 6 7 8 9 10
-Q8: B A B B A B D E D E


Their validity with their respective stated caveats may be confirmed by double clicking them in the linked webpage and seeing that all but the mentioned question are green.

I found these using Python code (below) which runs through all possible answer-sets and implements a piece of logic for each of questions 1 through 9 (10 not providing any check itself), with the ability to ignore any such checks.

Running it without removing any checks yields zero solutions.

Removing any other such single direct-implication check yields 0 solutions. Removing two yields single solutions for (1,7) and (5,7) removing 3 yields single solutions for (3,7,9) and (4,6,9).

If anyone can see any flaws in my manual step-by-step approach do shout. The most likely reason for both this and my Python code to come up empty will be a misinterpretation of their rules. I also attempted interpreting Q7 as having consecutive letters be "0 apart" rather than "1 apart" which also yielded 0 solutions. Another thought I had was to interpret Q5 as needing the one and only set of exactly two equal answers to be as given in the chosen answer, but this immediately leads to 0 solutions as there are 10 questions and 5 choices.

Python code (note: ignoreChecksForQuestions is 1-indexed. The implementation is 0-indexed, so for example if doThese[4]: and answers[4] are referring to question 5.)

from itertools import product

results = []
doThese = [q+1 not in ignoreChecksForQuestions for q in range(10)]
if doThese[4]:
if doThese[2]:
numberOfEs = sum(a=='E' for a in answers)
if ' ABCDE     '[numberOfEs] != answers[2]: continue
if doThese[3]:
numberOfAs = sum(a=='A' for a in answers)
if ' ABCDE     '[numberOfAs] != answers[3]: continue
if doThese[6]:
if doThese[7]:
if doThese[8]:
consonants = sum(a in 'BCD' for a in answers)
if '   ABCDE   '[consonants] != answers[8]: continue
if doThese[0]:
if '   EDCBA   '[firstDIndex] != answers[0]: continue
if doThese[5]:
if ' EDCBA     '[lastBRevIndex] != answers[5]: continue
if doThese[1]:
# note Q10 - all five answers self-validate


Example run:

>>> for answer in iterAnswers([5]): answer
...
('B', 'A', 'B', 'B', 'E', 'B', 'D', 'E', 'D', 'A')
>>>


Since writing this I looked at the paper written by the authors. This question-set was supposedly generated from another question-set for which the answers are given (they were the inputs to the process). The original question-set, to my mind, works perfectly. The paper does did (this has now been fixed) have one slight difference in the wording of the generated question-set to that presented in the webpage and here: Question 5 reads "The number of questions with the answer A equals the number of questions with the answer (A) A (B) B (C) D (D) E (E) none of the above". However this does did not strike me as a game-changer since either we start with Q5 must be A OR we allow E to be chosen when it is not only A. Maybe the check for Q5 is implemented differently by the webpage than how the authors meant it to be interpreted? (it has been confirmed in the comments that "none of the above" is coded to be an invalid choice, although we do not yet know if that was the intention of the authors of the paper - if someone is good with propositional logic they may be able to work it out from the tree they show there.).

• Flaw in your manual logic - answer to 5 could be also B, C or D. Say there are 2 As and 2 Bs (after B is selected) - it would be a valid answer. I haven't tried solving it yet to see if it changes result, but given single solution E for excluded Q5 it doesn't seem to work. And I suggest putting checks in order, it would make it easier to read the code :) – Zizy Archer Apr 20 '17 at 7:43
• @Zizy Thanks for looking, do see the rest - I have done it completely ignoring Q5 via code, and run that on the linked webpage - it marks it as entirely correct except Q5! Furthermore if we interpret 5 in that manner then we should interpret 2 similarly, which invalidates all possible answer-sets. – Jonathan Allan Apr 20 '17 at 7:46
• @Zizzy also note that if treated strictly Q5 can only be A - since if the number of As equals the number of Bs, then while both option A and option B are indeed true neither may be actually be picked (as it is not a unique answer). The wording used for E is "none of the above" which cannot strictly be picked ever (if it were "none or multiple of the above" it could). That only leaves A. – Jonathan Allan Apr 20 '17 at 7:54
• Oh, and the checks in the code presented are in order of computational complexity; none of them affect any of the others and they are effectively labelled by the if doThese statements. If ease of reading were paramount the tests would not index into strings and the questions would be 1-indexed etc. etc. – Jonathan Allan Apr 20 '17 at 8:03
• Well, not really. For that individual question both A and B would be valid. However, there are other questions that might prevent 5 from being A but not B. As for code, I know it doesn't influence anything, but it would be a bit easier to read and check if there are mistakes if it followed question order. – Zizy Archer Apr 20 '17 at 8:09