Re: Non dominating queens problem



"TS" <chewthiamsoon@xxxxxxxxx> writes:
> Hi, anyone got any solution in prolog to the non dominating queens problem?

Certainly. Have fun.


/* n-queens problem Thom Fruehwirth 1988 modified 910308 */

% place_queen(Queen,Column,Updiagonal,Downdiagonal) places a single queen
% Its the same for all versions

place_queen(I,[I|_],[I|_],[I|_]).
place_queen(I,[_|Cs],[_|Us],[_|Ds]):-
place_queen(I,Cs,Us,Ds).

% Pure version with successor function 1.92

queensp(N,Qs):- gen_listp(N,Qs), place_queensp(N,Qs,_,_).

gen_listp(0,[]).
gen_listp(s(N),[_|L]):-
gen_listp(N,L).

place_queensp(0,_,_,_).
place_queensp(s(I),Cs,Us,[_|Ds]):-
place_queensp(I,Cs,[_|Us],Ds),
place_queen(s(I),Cs,Us,Ds).

--
mailto:jjk@xxxxxxx As the air to a bird, or the sea to a fish,
http://www.bawue.de/~jjk/ so is contempt to the contemptible. [Blake]
http://del.icio.us/jjk
.