Home‎ > ‎

Blocked ECLiPSe

%
% ECLiPSe (eclipseclp.org) sample program with input and output
% as specified for the ICLP/CP2015 programming contest
%
% "Blocked Queens" (http://picat-lang.org/lp_cp_pc/BlockedQueens.html)
%
% Invocation:	eclipse -e main -f bq.ecl -f datafile.pl
%
% Author: Joachim Schimpf.  Use at your own risk for any purpose.
%

:- lib(ic).

main :-
	% expects facts for board(N) and block(R,C)
	board(N),
	findall(block(R,C), block(R,C), Blocks),

	dim(Qs, [N]),
	dim(Us, [N]),
	dim(Ds, [N]),
	Qs :: 1..N,
	( for(C,1,N), param(Qs,Us,Ds) do
	    Us[C] #= Qs[C]+C,
	    Ds[C] #= Qs[C]-C
	),
	alldifferent(Qs),
	alldifferent(Us),
	alldifferent(Ds),
	( foreach(block(R,C),Blocks), param(Qs) do
	    Qs[R] #\= C
	),

	search(Qs, 0, first_fail, indomain_middle, complete, []),

	( foreacharg(Q,Qs,C) do
	    write_term(queen(C,Q), [fullstop(true),nl(true)])
	).
Comments