
-----------------------------------
Cervantes
Sun Oct 31, 2004 10:10 pm

To Solve NQueen's
-----------------------------------
I was flipping back through some of the programs I've made and, after looking at 
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:

_______
|    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 :eh:
Cheers

-----------------------------------
Delos
Sun Oct 31, 2004 10:20 pm


-----------------------------------
Hmmm...I'm not sure if I understood your question, but you could do something like this:

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...

-----------------------------------
Cervantes
Mon Nov 01, 2004 3:42 pm


-----------------------------------
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.

-----------------------------------
bugzpodder
Mon Nov 01, 2004 3:55 pm


-----------------------------------
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.

-----------------------------------
Cervantes
Mon Nov 01, 2004 6:07 pm


-----------------------------------
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)
