1
0
This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
Jip J. Dekker fad1b07018 Squashed 'software/minizinc/' content from commit 4f10c8205
git-subtree-dir: software/minizinc
git-subtree-split: 4f10c82056ffcb1041d7ffef29d77a7eef92cf76
2021-06-16 14:06:46 +10:00

63 lines
1.3 KiB
MiniZinc

/***
!Test
expected:
- !Result
solution: !Solution
p:
- 1
- 2
- 1
- !Result
solution: !Solution
p:
- 2
- 2
- 1
***/
% Regression test for MiniZinc bug #109.
% mzn2fzn 1.1 was incorrectly flattening predicate arguments in a reifying
% context. Thiw as leading to the generated model instance being
% inconsistent.
% Smullyan Knights and Knaves problems in MiniZinc.
%
%
% These are the problems 26 to 35 from Raymond Smullyan's wonderful book
% "What is the name of this book? - The riddle of dracula and
% other logical puzzles".
%
%
% Model created by Hakan Kjellerstrand, hakank@bonetmail.com
% See also my MiniZinc page: http://www.hakank.org/minizinc
int: knight = 1; % alway tells the truth
int: knave = 2; % always lies
array[1..3] of var {knight, knave}: p;
% a knight always speaks the truth
% a knave always lies
%
% says(kind of person, what the person say)
%
predicate says(var int: kind, var bool: says) =
(kind = knight /\ says = true )
\/
(kind = knave /\ says = false )
;
constraint
%% Problem 27
%% B: A said that there are exactly 1 knights
%% C: B is a knave
%% What are B and C
%% Solution: B: knave, C: knight
says(p[2], says(p[1], 1 = sum(i in 1..3) (bool2int(p[i] = 1))))
/\
says(p[3], p[2] = knave);
solve satisfy;
output ["p = ", show(p), ";\n"];