Skip to content

Commit

Permalink
[#12] Feat: Add N-Queen
Browse files Browse the repository at this point in the history
  • Loading branch information
letsjo committed Apr 12, 2023
1 parent f9912be commit 8e37d4f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 9663.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# N-Queen
# PyPy3 로 완료

N = int(input())
count = 0
chessBoard = [0] * N
# (x,y) = (index,value)


def checkChessBoard(col):
for i in range(col):
if (chessBoard[col] == chessBoard[i] or abs(col-i) == abs(chessBoard[col]-chessBoard[i])):
return False
return True


def nQueen(col):
global count
if (col == N):
count += 1
return

for row in range(N):
chessBoard[col] = row
if (checkChessBoard(col)):
nQueen(col+1)


nQueen(0)
print(count)

0 comments on commit 8e37d4f

Please sign in to comment.