/*
7.A farmer leaves 45 casks of wine, of which 9 each are full,
three-quarters full, half full, one quarter full and empty. His five
nephews want to divide the wine and the casks without changing wine
from cask to cask in such a way that each receives the same amount of
wine and the same number of casks, and further so that each receives
at least one of each kind of cask, and no two of them receive the same
number of every kind of cask. (Kraitchik)
*/
:- lib(ic).
:- lib(ic_global).
:- lib(matrix_util).
solve(Casks) :-
% model
matrix(5, 9, Sons, Cols),
( foreach(Son, Sons) do
ordered(== 1
)
),
all_different_lists(Sons),
% search
( foreach(Col, Cols) do
( foreach(Cask, Col) do
indomain(Cask)
)
),
( foreach(Son, Sons) do % print solution
writeln(Son)
).
% auxiliary constraint definition
all_different_lists(Sons) :-
( fromto(Sons, [Son1|Sons1], Sons1, []) do
( foreach(Son2, Sons1), param(Son1) do
Son1 ~= Son2
)
).