% there are n teams - the number of teams is odd % so, we assume that it is of the form 2k+1 % and will receive the input k % and define a constant n const n = 2*k + 1. const ngames = k*(2*k+1). team(1..n). location(1..n). #domain team(T1;T2;T3;T4). % each pair of teams (X,Y) plays one game, at the location % of the first team or the second team 2*ngames { game(X,Y,Z) : team(X) : team(Y) : location(Z) } 2*ngames. % a team does not play itself :- game(T1,T1,T3). % teams do not play at neutral place :- game(T1,T2,T3), neq(T1,T3), neq(T2,T3). % each pair plays only one % one game is scheduled only one :- game(T1,T2,T3), game(T1,T2,T4), neq(T3,T4). % if A plays B means that B plays A game(T2,T1,T3) :- game(T1,T2,T3). % there should be only k games at each location -- we count each % game as play twice so there should be only 2k games at each % location -- if there are more than that (2k+1 is n) it is % not a good schedule :- n { game(X,Y,Z) : team(X) : team(Y) }, location(Z). hide team(_). hide location(_).