-
Notifications
You must be signed in to change notification settings - Fork 0
/
queens.pl
22 lines (16 loc) · 873 Bytes
/
queens.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function(INT, Input) :- length(Input, INT), queens(Input, Board, 0, INT, _, _), queens(Board, 0, Input).
queens([], [], Numbers, Numbers, _, _).
queens([_| Numbers], [Column - NewColumns | Board], ZeroColumn,
N, [_| FirstRows], FirstColumns) :- Column is ZeroColumn + 1,
functor(NewColumns, f, N),
constraints(N, NewColumns, FirstRows, FirstColumns),
queens(Numbers, Board, Column, N, FirstRows, [_|FirstColumns]).
constraints(0, _, _, _) :- !.
constraints(INT, NewRow, [Row | RowSearch], [Column | ColumnSearch]) :- arg(INT, NewRow, Row-Column),
Initial is INT - 1,
constraints(Initial, NewRow, RowSearch, ColumnSearch).
queens([], _, []).
queens([Column | ColumnSearch], ZeroRow, [NewColumn | Return]) :- NewRow is ZeroRow + 1,
select(NewColumn - INTS, [Column | ColumnSearch], PlayingFunc),
arg(NewRow, INTS, NewRow - NewRow),
queens(PlayingFunc, NewRow, Return).