0% found this document useful (0 votes)
35 views1 page

Program 8queens

This document defines domains, predicates, and clauses for solving the N queens problem using logic programming. It defines cells as integer pairs, a list as a collection of cells, and predicates for a list being a solution, an integer being a member of a list, and cells not attacking each other in a list.

Uploaded by

AdiseshuMidde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views1 page

Program 8queens

This document defines domains, predicates, and clauses for solving the N queens problem using logic programming. It defines cells as integer pairs, a list as a collection of cells, and predicates for a list being a solution, an integer being a member of a list, and cells not attacking each other in a list.

Uploaded by

AdiseshuMidde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

domains

cell=c(integer,integer)
list=cell*
int_list=integer*
predicates
solution(list)
member(integer,int_list)
nonattack(cell,list)
clauses
solution([]).
solution([c(X,Y)|Others]):-
solution(Others),
member(Y,[1,2,3,4,5,6,7,8]),
nonattack(c(X,Y),Others).
nonattack(_,[]).
nonattack(c(X,Y),[c(X1,Y1)|Others]):-
Y<>Y1,
Y1-Y<>X1-X,
Y1-Y<>X-X1,
nonattack(c(X,Y),Others).
member(X,[X|_]).
member(X,[_|Z]):-
member(X,Z).

You might also like