⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bqueens.pl

📁 PRl教学程序 PRl教学程序 PRl教学程序
💻 PL
字号:
/*-------------------------------------------------------------------------*/
/* Benchmark (Boolean)                                                     */
/*                                                                         */
/* Name           : bqueens.pl                                             */
/* Title          : N-queens problem                                       */
/* Original Source: Daniel Diaz - INRIA France                             */
/* Adapted by     : Daniel Diaz for CLP(FD)                                */
/* Date           : January 1993                                           */
/*                                                                         */
/* Put N queens on an NxN chessboard so that there is no couple of queens  */
/* threatening each other.                                                 */
/* The solution is a list [ [Que11,...,Que1N], ... ,[QueN1,...,QueNN] ]    */
/* where Queij is 1 if the the  is a queen on the ith line an jth row.     */
/*                                                                         */
/* Solution:                                                               */
/* N=4  [[0,0,1,0],         [[0,1,0,0],                                    */
/*       [1,0,0,0],          [0,0,0,1],                                    */
/*       [0,0,0,1],  and     [1,0,0,0],                                    */
/*       [0,1,0,0]]          [0,0,1,0]]                                    */
/*                                                                         */
/* N=8  [[0,0,0,0,0,0,0,1], (first solution)                               */
/*       [0,0,0,1,0,0,0,0],                                                */
/*       [1,0,0,0,0,0,0,0],                                                */
/*       [0,0,1,0,0,0,0,0],                                                */
/*       [0,0,0,0,0,1,0,0],                                                */
/*       [0,1,0,0,0,0,0,0],                                                */
/*       [0,0,0,0,0,0,1,0],                                                */
/*       [0,0,0,0,1,0,0,0]]                                                */
/*-------------------------------------------------------------------------*/
:-write('you need array.pl (www.probp.com/libraryplus/array.pl) to run this program.'),nl.

go:-	
    statistics(runtime,_),
    top,
    statistics(runtime,[_,Y]),
    write('time : '), write(Y), nl.

top:-
    N=8,
    (bqueens(N,A), 
     write(A), nl,
     fail
     ; 
     write('No more solutions'), nl).

bqueens(N,A):-
    create_array(N,N,A),
    for_each_line(A,fd_only_one),
    for_each_column(A,fd_only_one),
    for_each_diagonal(A,fd_at_most_one),
    !,
    array_labeling(A).

:-load(array).





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -