N 4 Nqueens Problem
N 4 Nqueens Problem
def printSolution(board):
for i in range(N):
for j in range(N):
print(board[i][j], end=' ')
print()
return True
for i in range(N):
if isSafe(board, i, col):
# Place this queen in board[i][col]
board[i][col] = 1
# If the queen cannot be placed in any row in this column, return false
return False
def solveNQ():
board = [[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
printSolution(board)
return True
# Driver program to test the above function
solveNQ()
output:
0 0 1 0
1 0 0 0
0 0 0 1
0 1 0 0