/* queens_clpdf benchmark in Picat v3. bench/queens_clpfd.pl https://github.com/SWI-Prolog/bench Changes: - added "import cp" instead of ":- use_module(library(clpfd))" - replaced "ins" to "::" (for the domain) Note: This benchmark don't actually solve the 200-queens problems. Using solve (or label in the SWI-Prolog model) to just show the first solution is slow. Showing _all_ solutions (using fail/0) is even slower. From https://en.wikipedia.org/wiki/Eight_queens_puzzle#Counting_solutions The total number of solutions for just 27-queens is 234,907,967,154,122,528. Thus, this model behaves as the SWI Prolog model. Solving for first solutions of N=200 takes 2.6s which is not especially fast. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. % Solving first solution: 2.588s go ?=> n_queens(200,Q), solve($[ff],Q), println(Q), % fail, nl. go => true. % """ % Copied from https://swish.swi-prolog.org/example/clpfd_queens.pl % Author: Markus Triska % """ top :- n_queens(8,Q),solve($[ff,split],Q), fail. top. n_queens(N, Qs) :- bp.length(Qs, N), Qs :: 1..N, safe_queens(Qs). safe_queens([]). safe_queens([Q|Qs]) :- safe_queens(Qs, Q, 1), safe_queens(Qs). safe_queens([], _, _). safe_queens([Q|Qs], Q0, D0) :- Q0 #!= Q, abs(Q0 - Q) #!= D0, D1 #= D0 + 1, safe_queens(Qs, Q0, D1).