# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
def isValid(board, row, col):
for i in range(row):
if board[i] == col or abs(board[i] - col) == abs(i - row):
return False
return True
def eightQueens(board, row):
print(f"borad: {board}, row: {row}")
if row == 8:
print("finally:")
print(board)
print("-"*20)
return
for i in range(8):
if isValid(board, row, i):
board[row] = i
eightQueens(board, row + 1)
eightQueens([-1] * 8, 0)
沒有留言:
張貼留言