Skip to content

Commit

Permalink
Working implementation - needs testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michelle Foy committed Sep 25, 2017
1 parent cedafc3 commit e03fc7e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions queensplace.pl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
% This is a program for Queens Placement
findSolution([]).

findSolution([X/Y | Others]) :- findSolution(Others),
member(Y, [1, 2, 3, 4, 5, 6, 7, 8]),
doNotAttack(X/Y, Others), !.
findSolutions([]).
findSolutions([X/Y | Others]) :- findSolutions(Others),
member(Y, [1, 2, 3, 4, 5, 6, 7, 8]),
doNotAttack(X/Y, Others).

doNotAttack(_, []).

doNotAttack(X/Y,[X1/Y1 | Others]) :- Y =\= Y1,
Y1 - Y =\= X1 - X,
Y1 - Y =\= X - X1,
doNotAttack(X/Y, Others).

% To get solutions:
% findSolutions([1/A,2/B,3/C,4/D,5/E,6/F,7/G,8/H]).

0 comments on commit e03fc7e

Please sign in to comment.