Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 To Solve NQueen's
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Cervantes




PostPosted: 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 Eh
Cheers
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: 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...
Cervantes




PostPosted: 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.
bugzpodder




PostPosted: 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.
Cervantes




PostPosted: 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)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: