Skip to content

Instantly share code, notes, and snippets.

@yask123
Created June 13, 2016 13:35
Show Gist options
  • Save yask123/8a39da74cc5b32a412eab795a89df30d to your computer and use it in GitHub Desktop.
Save yask123/8a39da74cc5b32a412eab795a89df30d to your computer and use it in GitHub Desktop.
def check(row,column,board):
for i in range(N):
if board[row][i] == 'Q':
return False
return True
def solve_queen(current_column, board):
if current_column == -1:
print board
return True
for i in range(len(board)):
if check(i,current_column,board):
board[i][current_column] = 'Q'
if not solve_queen(current_column-1,board):
board[i][current_column] = '*'
N = 4
board = [[None]*4]*4
print solve_queen(N-1,board)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment