To Solve NQueen's
Author |
Message |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sun Oct 31, 2004 10:10 pm Post subject: To Solve NQueen's |
|
|
I was flipping back through some of the programs I've made and, after looking at NQueen's, I decided I'd try to make a graphical program that would systematically go through each possibility and spit out each and every solution.
Here's what I mean by a systematic run through.
code: |
for a : 1 .. 3
for b : 1 .. 3
for c : 1 .. 3
put a, "-", b, "-", c
end for
end for
end for
|
a, b, and c represent the columns, and their number value represents the row.
so, when that code outputs "2-2-3", a graphical interpretation of that would be like the following:
code: |
_______
| x|
|x x |
|_____|
|
The problem is, I have a 2D boolean array to store the information about the grid; how would I take information like "2-2-3" and put it into a 2D array? Preferably, I'd like to stay away from string manipulation, if at all possible, and work it out purely with for loops. I don't know if it's possible, I surely can't uncover the solution, maybe someone else can.
I hope you understood my question
Cheers |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Sun Oct 31, 2004 10:20 pm Post subject: (No subject) |
|
|
Hmmm...I'm not sure if I understood your question, but you could do something like this:
code: |
for i : 1..3
for j : 1..3
for k : 1..3
queensArray (i) := true
queensArray (j) := true
queensArray (k) := true
% check validity.
end for
end for
end for
|
But this isn't all that worthwhile since it's limited to just N=3. I can see the actual code floating on the periphery of my concious, but I'm not in the frame of mind right now to tear it into my vision...sorry. Something about recursion... |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Mon Nov 01, 2004 3:42 pm Post subject: (No subject) |
|
|
so, for an 8x8 grid, I'd have 8 seperate arrays? I suppose that could work, but I was hoping to be able to have the user select the size of the grid. |
|
|
|
|
![](images/spacer.gif) |
bugzpodder
![](http://www.vbforums.com/avatar.php?userid=31755&dateline=1038631511)
|
Posted: Mon Nov 01, 2004 3:55 pm Post subject: (No subject) |
|
|
you need some recursion to make it work. keep an array of size 8 (for 8x8 boards) for the position of the queens in each row. |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Mon Nov 01, 2004 6:07 pm Post subject: (No subject) |
|
|
bugzpodder wrote: keep an array of size 8 (for 8x8 boards) for the position of the queens in each row.
That's what I was doing.
Unfortunately, I'm no good with recursion 8) |
|
|
|
|
![](images/spacer.gif) |
|
|