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.
 
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Back
Top