Writing a Recursive Function for Placing n Queens on an n x n Chessboard

AI Thread Summary
The discussion revolves around creating a recursive function to place n Queens on an n x n chessboard, ensuring that no two Queens can attack each other. The initial task is manageable, but the challenge lies in developing a second recursive function to find all possible safe arrangements of the Queens. Clarification is sought regarding the definition of "all possible solutions," which is confirmed to mean finding every configuration where the Queens do not threaten one another. A resource link is provided for further assistance on the topic.
discoverer02
Messages
138
Reaction score
1
I have an assignment to write a recursive function that will safely place n Queens on an n x n chessboard. This wasn't all that difficult to figure out.

For extra credit I'm supposed to write another function(s) (recursive?) that figures out all the possible solutions. This is, so far, giving me fits.

Any nudge in the right direction would be greatly appreciated.
 
Last edited:
Computer science news on Phys.org
Can you be a little more specific in what you mean by figure out all the possible solutions? Do you mean once you place all the queens on the board, find all the possible moves which lead to a checkmate? That might take a while, especially if you have a bunch of queens. It is on the exponential scale.
 
Sorry for not being clear. By solutions, I mean all the possible ways I can place the Queens safely. ie. No Queen can attack another Queen on the board.
 
Thanks dduardo.
 
This week, I saw a documentary done by the French called Les sacrifiés de l'IA, which was presented by a Canadian show Enquête. If you understand French I recommend it. Very eye-opening. I found a similar documentary in English called The Human Cost of AI: Data workers in the Global South. There is also an interview with Milagros Miceli (appearing in both documentaries) on Youtube: I also found a powerpoint presentation by the economist Uma Rani (appearing in the French documentary), AI...
Back
Top