| 1 |
/*** |
| 2 |
!Test |
| 3 |
expected: |
| 4 |
- !Result |
| 5 |
solution: !Solution |
| 6 |
p: |
| 7 |
- 1 |
| 8 |
- 2 |
| 9 |
- 1 |
| 10 |
- !Result |
| 11 |
solution: !Solution |
| 12 |
p: |
| 13 |
- 2 |
| 14 |
- 2 |
| 15 |
- 1 |
| 16 |
***/ |
| 17 |
|
| 18 |
% Regression test for MiniZinc bug #109. |
| 19 |
% mzn2fzn 1.1 was incorrectly flattening predicate arguments in a reifying |
| 20 |
% context. Thiw as leading to the generated model instance being |
| 21 |
% inconsistent. |
| 22 |
|
| 23 |
% Smullyan Knights and Knaves problems in MiniZinc. |
| 24 |
% |
| 25 |
% |
| 26 |
% These are the problems 26 to 35 from Raymond Smullyan's wonderful book |
| 27 |
% "What is the name of this book? - The riddle of dracula and |
| 28 |
% other logical puzzles". |
| 29 |
% |
| 30 |
% |
| 31 |
% Model created by Hakan Kjellerstrand, [email protected] |
| 32 |
% See also my MiniZinc page: http://www.hakank.org/minizinc |
| 33 |
|
| 34 |
int: knight = 1; % alway tells the truth |
| 35 |
int: knave = 2; % always lies |
| 36 |
|
| 37 |
array[1..3] of var {knight, knave}: p; |
| 38 |
|
| 39 |
% a knight always speaks the truth |
| 40 |
% a knave always lies |
| 41 |
% |
| 42 |
% says(kind of person, what the person say) |
| 43 |
% |
| 44 |
predicate says(var int: kind, var bool: says) = |
| 45 |
(kind = knight /\ says = true ) |
| 46 |
\/ |
| 47 |
(kind = knave /\ says = false ) |
| 48 |
; |
| 49 |
|
| 50 |
constraint |
| 51 |
%% Problem 27 |
| 52 |
%% B: A said that there are exactly 1 knights |
| 53 |
%% C: B is a knave |
| 54 |
%% What are B and C |
| 55 |
%% Solution: B: knave, C: knight |
| 56 |
says(p[2], says(p[1], 1 = sum(i in 1..3) (bool2int(p[i] = 1)))) |
| 57 |
/\ |
| 58 |
says(p[3], p[2] = knave); |
| 59 |
|
| 60 |
solve satisfy; |
| 61 |
|
| 62 |
output ["p = ", show(p), ";\n"]; |