Created
June 13, 2016 13:35
-
-
Save yask123/8a39da74cc5b32a412eab795a89df30d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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