1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
:- use_module(library(clpfd)).
count(E,L,N):-partition(=(E),L,Include,_),length(Include,N1),N #= N1.
quizz(Solution) :-
Solution=[Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,Q10,Q11,Q12,Q13,Q14,Q15,Q16,Q17,Q18,Q19,Q20],
SolBegin=[Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,Q10],
SolEnd=[Q11,Q12,Q13,Q14,Q15,Q16,Q17,Q18,Q19,Q20],
% N1=nb_of_A, N2a=nb_of_B[1..10], N2b=nb_of_B[11..20], N3=nb_of_C, N4=nb_of_D, N5=nb_of_E
Counts=[N1,N2a,N2b,N3,N4,N5],
Solution ins 1..5,
Counts ins 0..20,
N1 + N2a + N2b + N3 + N4 + N5 #= 20,
% A=1, B=2, C=3, D=4, E=5
% 1. the first question whose answer is B is question 1/1 2/2 3/3 4/4 5/5
Q1 #= 1 #<==> Q1 #= 2,
Q1 #= 2 #<==> Q1 #\= 2 #/\ Q2 #= 2,
Q1 #= 3 #<==> Q1 #\= 2 #/\ Q2 #\= 2 #/\ Q3 #= 2,
Q1 #= 4 #<==> Q1 #\= 2 #/\ Q2 #\= 2 #/\ Q3 #\= 2 #/\ Q4 #= 2,
Q1 #= 5 #<==> Q1 #\= 2 #/\ Q2 #\= 2 #/\ Q3 #\= 2 #/\ Q4 #\= 2 #/\ Q5 #= 2,
% 2. The only two consecutive questions with identical answers are questions 1/ 6 and 7, 2/ 7 and 8, 3/ 8 and 9, 4/ 9 and 10, 5/ 10 and 11
Q2 #= 1 #<==> Q6 #= Q7 #/\ Q7 #\= Q8 #/\ Q8 #\= Q9 #/\ Q9 #\= Q10 #/\ Q10 #\= Q11,
Q2 #= 2 #<==> Q6 #\= Q7 #/\ Q7 #= Q8 #/\ Q8 #\= Q9 #/\ Q9 #\= Q10 #/\ Q10 #\= Q11,
Q2 #= 3 #<==> Q6 #\= Q7 #/\ Q7 #\= Q8 #/\ Q8 #= Q9 #/\ Q9 #\= Q10 #/\ Q10 #\= Q11,
Q2 #= 4 #<==> Q6 #\= Q7 #/\ Q7 #\= Q8 #/\ Q8 #\= Q9 #/\ Q9 #= Q10 #/\ Q10 #\= Q11,
Q2 #= 5 #<==> Q6 #\= Q7 #/\ Q7 #\= Q8 #/\ Q8 #\= Q9 #/\ Q9 #\= Q10 #/\ Q10 #= Q11,
% 3. The number of questions with the answer E is 1/ 0, 2/ 1, 3/ 2, 4/ 3, 5/ 4
Q3 #= 1 #<==> N5 #= 0,
Q3 #= 2 #<==> N5 #= 1,
Q3 #= 3 #<==> N5 #= 2,
Q3 #= 4 #<==> N5 #= 3,
Q3 #= 5 #<==> N5 #= 4,
% 4. The number of questions with the answer A is 1/ 4, 2/ 5, 3/ 6, 4/ 7, 5/ 8
Q4 #= 1 #<==> N1 #= 4,
Q4 #= 2 #<==> N1 #= 5,
Q4 #= 3 #<==> N1 #= 6,
Q4 #= 4 #<==> N1 #= 7,
Q4 #= 5 #<==> N1 #= 8,
% 5. The answer to this question is the same as the answer to question 1/ 1, 2/ 2, 3/ 3, 4/ 4, 5/ 5
Q5 #= 1 #<==> Q1 #= 1,
Q5 #= 2 #<==> Q2 #= 2,
Q5 #= 3 #<==> Q3 #= 3,
Q5 #= 4 #<==> Q4 #= 4,
Q5 #= 5 #<==> Q1 #\= 1 #/\ Q2 #\= 2 #/\ Q3 #\= 3 #/\ Q4 #\= 4,
% 6. The answer to question 17 is 1/ C, 2/ D, 3/ E, 4/ none of the above, 5/ all of the above
Q6 #= 1 #<==> Q17 #= 3,
Q6 #= 2 #<==> Q17 #= 4,
Q6 #= 3 #<==> Q17 #= 5,
Q6 #= 4 #<==> Q17 #\= 3 #/\ Q17 #\= 4 #/\ Q17 #\= 5,
Q6 #= 5 #<==> Q17 #= 3 #/\ Q17 #= 4 #/\ Q17 #= 5,
% 7. Alphabetically, the answer to this question and the answer to the following question are 1/ 4 apart, 2/ 3 apart, 3/ 2 apart, 4/ 1 apart, 5/ the same
Q7 #= 1 #<==> Q8 - Q7 #= 4,
Q7 #= 2 #<==> Q8 - Q7 #= 3,
Q7 #= 3 #<==> Q8 - Q7 #= 2 #\/ Q7 - Q8 #= 2,
Q7 #= 4 #<==> Q8 - Q7 #= 1 #\/ Q7 - Q8 #= 1,
Q7 #= 5 #<==> Q8 #= Q7,
% 8. The number of questions whose answers are vowels is 1/ 4, 2/ 5, 3/ 6, 4/ 7, 5/ 8
Q8 #= 1 #<==> N1 + N5 #= 4,
Q8 #= 2 #<==> N1 + N5 #= 5,
Q8 #= 3 #<==> N1 + N5 #= 6,
Q8 #= 4 #<==> N1 + N5 #= 7,
Q8 #= 5 #<==> N1 + N5 #= 8,
% 9. The next question with the same answer as this one is question 1/ 10, 2/ 11, 3/ 12, 4/ 13, 5/ 14
Q9 #= 1 #<==> Q10 #= Q9,
Q9 #= 2 #<==> Q10 #\= 2 #/\ Q11 #= Q9,
Q9 #= 3 #<==> Q10 #\= 3 #/\ Q11 #\= 3 #/\ Q12 #= Q9,
Q9 #= 4 #<==> Q10 #\= 4 #/\ Q11 #\= 4 #/\ Q12 #\= 4 #/\ Q13 #= Q9,
Q9 #= 5 #<==> Q10 #\= 5 #/\ Q11 #\= 5 #/\ Q12 #\= 5 #/\ Q13 #\= 5 #/\ Q14 #= Q9,
% 10. the answer to question 16 is 1/4, 2/1, 3/5, 4/2, 5/3
Q10 #= 1 #<==> Q16 #= 4,
Q10 #= 2 #<==> Q16 #= 1,
Q10 #= 3 #<==> Q16 #= 5,
Q10 #= 4 #<==> Q16 #= 2,
Q10 #= 5 #<==> Q16 #= 3,
% 11. The number of questions preceding this one with the answer B is 1/ 0, 2/ 1, 3/ 2, 4/ 3, 5/ 4
Q11 #= 1 #<==> N2a #= 0,
Q11 #= 2 #<==> N2a #= 1,
Q11 #= 3 #<==> N2a #= 2,
Q11 #= 4 #<==> N2a #= 3,
Q11 #= 5 #<==> N2a #= 4,
% 12. The number of questions whose answer is a consonant is 1/ an even number, 2/ an odd number, 3/ a perfect square, 4/ a prime, 5/ divisible by 5
Q12 #= 1 #<==> (N2a + N2b + N3 + N4) mod 2 #= 0,
Q12 #= 2 #<==> (N2a + N2b + N3 + N4) mod 2 #= 1,
Q12 #= 4 #<==> (N2a + N2b + N3 + N4) #= 1 #\/ (N2a + N2b + N3 + N4) #= 4 #\/ (N2a + N2b + N3 + N4) #= 9 #\/ (N2a + N2b + N3 + N4) #= 16,
Q12 #= 4 #<==> (N2a + N2b + N3 + N4) #= 2 #\/ (N2a + N2b + N3 + N4) #= 3 #\/ (N2a + N2b + N3 + N4) #= 5 #\/ (N2a + N2b + N3 + N4) #= 7 #\/ (N2a + N2b + N3 + N4) #= 11 #\/ (N2a + N2b + N3 + N4) #= 13 #\/ (N2a + N2b + N3 + N4) #= 17 #\/ (N2a + N2b + N3 + N4) #= 19,
Q12 #= 5 #<==> (N2a + N2b + N3 + N4) mod 5 #= 0,
% 13. The only odd-numbered problem with answer A is 1/ 9, 2/ 11, 3/ 13, 4/ 15, 5/ 17
Q13 #= 1 #<==> Q1 #\= 1 #/\ Q3 #\= 1 #/\ Q5 #\= 1 #/\ Q7 #\= 1 #/\ Q9 #= 1 #/\ Q11 #\= 1 #/\ Q13 #\= 1 #/\ Q15 #\= 1 #/\ Q17 #\= 1 #/\ Q19 #\= 1,
Q13 #= 2 #<==> Q1 #\= 1 #/\ Q3 #\= 1 #/\ Q5 #\= 1 #/\ Q7 #\= 1 #/\ Q9 #\= 1 #/\ Q11 #= 1 #/\ Q13 #\= 1 #/\ Q15 #\= 1 #/\ Q17 #\= 1 #/\ Q19 #\= 1,
Q13 #= 3 #<==> Q1 #\= 1 #/\ Q3 #\= 1 #/\ Q5 #\= 1 #/\ Q7 #\= 1 #/\ Q9 #\= 1 #/\ Q11 #\= 1 #/\ Q13 #= 1 #/\ Q15 #\= 1 #/\ Q17 #\= 1 #/\ Q19 #\= 1,
Q13 #= 4 #<==> Q1 #\= 1 #/\ Q3 #\= 1 #/\ Q5 #\= 1 #/\ Q7 #\= 1 #/\ Q9 #\= 1 #/\ Q11 #\= 1 #/\ Q13 #\= 1 #/\ Q15 #= 1 #/\ Q17 #\= 1 #/\ Q19 #\= 1,
Q13 #= 5 #<==> Q1 #\= 1 #/\ Q3 #\= 1 #/\ Q5 #\= 1 #/\ Q7 #\= 1 #/\ Q9 #\= 1 #/\ Q11 #\= 1 #/\ Q13 #\= 1 #/\ Q15 #\= 1 #/\ Q17 #= 1 #/\ Q19 #\= 1,
% 14. The number of questions with answer D is 1/ 6, 2/ 7, 3/ 8, 4/ 9, 5/ 10
Q14 #= 1 #<==> N4 #= 6,
Q14 #= 2 #<==> N4 #= 7,
Q14 #= 3 #<==> N4 #= 8,
Q14 #= 4 #<==> N4 #= 9,
Q14 #= 5 #<==> N4 #= 10,
% 15. The answer to question 12 is 1/ A, 2/ B, 3/ C, 4/ D, 5/ E
Q15 #= Q12,
% 16. the answer to question 10 is 1/4, 2/3, 3/2 ,4/1 ,5/5
Q16 #= 1 #<==> Q10 #= 4,
Q16 #= 2 #<==> Q10 #= 3,
Q16 #= 3 #<==> Q10 #= 2,
Q16 #= 4 #<==> Q10 #= 1,
Q16 #= 5 #<==> Q10 #= 5,
% 17. The answer to question 6 is 1/ C, 2/ D, 3/ E, 4/ none of the above, 5/ all of the above
Q17 #= 1 #<==> Q6 #= 3,
Q17 #= 2 #<==> Q6 #= 4,
Q17 #= 3 #<==> Q6 #= 5,
Q17 #= 4 #<==> Q6 #\= 3 #/\ Q6 #\= 4 #/\ Q6 #\= 5,
Q17 #= 5 #<==> Q6 #= 3 #/\ Q6 #= 4 #/\ Q6 #= 5,
% 18. The number of questions with answer A equals the number of questions with answer 1/ B, 2/ C, 3/ D, 4/ E, 5/ none of the above
Q18 #= 1 #<==> N1 #= N2a + N2b,
Q18 #= 2 #<==> N1 #= N3,
Q18 #= 3 #<==> N1 #= N4,
Q18 #= 4 #<==> N1 #= N5,
Q18 #= 5 #<==> N1 #\=N2a + N2b #/\ N1 #\= N3 #/\ N1 #\= N4 #/\ N1 #\= N5,
% 19. The answer to this question is 1/ A, 2/ B, 3/ C, 4/ D, 5/ E
% 20. Standardized test : intelligence :: barometer : 1/ temperature (only), 2/ wind-velocity (only), 3/ latitude (only), 4/ longitude (only), 5/ all of the above
label(Counts),
label(Solution),
count(1,Solution,N1),
count(2,SolBegin,N2a),
count(2,SolEnd,N2b),
count(3,Solution,N3),
count(4,Solution,N4),
count(5,Solution,N5)
.
all_solutions:-quizz(N),maplist(plus(64),N,M),maplist(put_char,M). |
Partager