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.

19 lines
663 B
MiniZinc

% the sum of booleans x = s
predicate bool_sum_eq(array[int] of var bool:x, int:s) =
let { int: c = length(x),
array[1..c] of var bool: y = [x[i] | i in index_set(x)]
} in
rec_bool_sum_eq(y, 1, s);
predicate rec_bool_sum_eq(array[int] of var bool:x, int: f, int:s) =
let { int: c = length(x) } in
if s < 0 then false
elseif s == 0 then
forall(i in f..c)(x[i] == false)
elseif s < c - f + 1 then
(x[f] == true /\ rec_bool_sum_eq(x,f+1,s-1)) \/
(x[f] == false /\ rec_bool_sum_eq(x,f+1,s))
elseif s == c - f + 1 then
forall(i in f..c)(x[i] == true)
else false endif;