Initial commit
This commit is contained in:
20
examples/NQueens.rp1
Normal file
20
examples/NQueens.rp1
Normal file
@@ -0,0 +1,20 @@
|
||||
; Each possible coordinate on the board.
|
||||
define output Coord Integer
|
||||
Coord 1.
|
||||
Coord a :- Coord b, b < 8, a = b + 1.
|
||||
|
||||
; Each possible placement of a queen.
|
||||
define output decision Queen(Coord, Coord)
|
||||
Queen(row, col) :- Coord row, Coord col.
|
||||
|
||||
; Exactly one queen goes on each row.
|
||||
:- For(row), @count Queen(row, _) = 1.
|
||||
|
||||
; Exactly one queen goes on each column.
|
||||
:- For(col), @count Queen(_, col) = 1.
|
||||
|
||||
; At most one queen can go along each main diagonal.
|
||||
:- For(diag), @count { Queen (row, col), diag = row + col } <= 1.
|
||||
|
||||
; At most one queen can go along each orthogonal diagonal.
|
||||
:- For(diag), @count { Queen (row, col), diag = row - col } <= 1.
|
||||
Reference in New Issue
Block a user