Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ United Kingdom - https://github.com/cu-sanjay/HacktoberFest2023/assets/96792511/
|[Darshit Dudhaiya](https://github.com/darshitdudhaiya) | <img src="https://github.com/cu-sanjay/HacktoberFest2023/assets/96792511/5adfd776-ce7e-4467-92dd-727a12239cd1" alt="India" width="32" height="32"> | I'm a Student and full-stack web developer and i enthusiast about coding. |
|[Naveen Kumar .v](https://github.com/NK-dev-24) | <img src="https://github.com/cu-sanjay/HacktoberFest2023/assets/96792511/5adfd776-ce7e-4467-92dd-727a12239cd1" alt="India" width="32" height="32"> | I'm a Student. |
|[Chandan Arya](https://github.com/alpha2lucifer) | <img src="https://github.com/cu-sanjay/HacktoberFest2023/assets/96792511/5adfd776-ce7e-4467-92dd-727a12239cd1" alt="India" width="32" height="32"> | I am a passionate developer with a keen interest in blockchain technology and decentralized applications. My focus lies in creating efficient and secure solutions, and I enjoy exploring various programming languages and frameworks to build innovative applications.|
|[Subhikshaa S](https://github.com/Subhikshaa23) | <img src="https://github.com/cu-sanjay/HacktoberFest2023/assets/96792511/5adfd776-ce7e-4467-92dd-727a12239cd1" alt="India" width="32" height="32"> | A passionate web developer and a curious learner |


32 changes: 32 additions & 0 deletions Python/NQueen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#N-Queens Problem
def attack(i, j):
for k in range(0,N):
if board[i][k]==1 or board[k][j]==1:
return True
for k in range(0,N):
for l in range(0,N):
if (k+l==i+j) or (k-l==i-j):
if board[k][l]==1:
return True
return False

def N_queens(n):
if n==0:
return True
for i in range(0,N):
for j in range(0,N):
if (not(attack(i,j))) and (board[i][j]!=1):
board[i][j] = 1
if N_queens(n-1)==True:
return True
board[i][j] = 0
return False

print ("Enter the number of queens: ")
N = int(input())
board = [[0]*N for _ in range(N)]

N_queens(N)
print("Solution:")
for i in board:
print (i)