diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 09f1c1f8..211c6bf8 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -32,5 +32,6 @@ United Kingdom - https://github.com/cu-sanjay/HacktoberFest2023/assets/96792511/ |[Darshit Dudhaiya](https://github.com/darshitdudhaiya) | India | I'm a Student and full-stack web developer and i enthusiast about coding. | |[Naveen Kumar .v](https://github.com/NK-dev-24) | India | I'm a Student. | |[Chandan Arya](https://github.com/alpha2lucifer) | India | 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) | India | A passionate web developer and a curious learner | diff --git a/Python/NQueen.py b/Python/NQueen.py new file mode 100644 index 00000000..5e3632b6 --- /dev/null +++ b/Python/NQueen.py @@ -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)