# Różnice

Różnice między wybraną wersją a wersją aktualną.

 — pl:prolog:pllib:8_queens_2 [2019/06/27 15:50] (aktualna) Linia 1: Linia 1: + ====== 8 queens 2 ====== + {{tag>​puzzle chess}} + ===== Description ===== + Program solves 8 queens problem + + **Source**: ​ PrologTutorial (on-line tutorial) + ===== Download ===== + Program source code: {{prolog:​pllib:​8_queens_2.pl}} + ===== Listing ===== + + /* prolog tutorial 2.11 Chess queens challenge puzzle */ + + perm([X|Y],​Z) :- perm(Y,W), takeout(X,​Z,​W). ​ + perm([],​[]). + + takeout(X,​[X|R],​R). + takeout(X,​[F|R],​[F|S]) :- takeout(X,​R,​S). + + solve(P) :- + ​perm([1,​2,​3,​4,​5,​6,​7,​8],​P), ​ + ​combine([1,​2,​3,​4,​5,​6,​7,​8],​P,​S,​D),​ + ​all_diff(S),​ + ​all_diff(D). + + combine([X1|X],​[Y1|Y],​[S1|S],​[D1|D]) :- + S1 is X1 +Y1, + D1 is X1 - Y1, + ​combine(X,​Y,​S,​D). + combine([],​[],​[],​[]). + + all_diff([X|Y]) :-  \+member(X,​Y),​ all_diff(Y). + all_diff([X]). + + + /* ?- solve(P). + P = [5,​2,​6,​1,​7,​4,​8,​3] ; + P = [6,​3,​5,​7,​1,​4,​2,​8] ; + ... + + ?- setof(P,​solve(P),​Set),​ length(Set,​L). + ... + L = 92 + */ + ​ + ===== Comments =====
pl/prolog/pllib/8_queens_2.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)