mkagenius's blog

By mkagenius, 14 years ago, In English
http://en.wikipedia.org/wiki/Eight_queens_puzzle#Sample_program

Here the program for 8 - queen puzzle.
But it is not working.
Plz tell what is the problem.


Here I tried to run it:

Earlier there was no 'x' in wikipedia I added 'x' there...
Am I correct and still it is not working.

PS:  I don't know pascal, so plz don't get me on this. :)

  • Vote: I like it
  • 0
  • Vote: I do not like it

14 years ago, # |
Rev. 7   Vote: I like it +1 Vote: I do not like it

In Russian Wikipedia there is solution in Basic, in Ukrainian Wikipedia there are solutions in Python and Prolog. You can take them even if you don't know Russian or Ukrainian. Also you can check other wiki's languages and find solution in program language that you know.

But take into account, that recursive backtracking works only for small boards. For large board many people recommend use simulated annealing. But as for me - good implemented random search works faster (100-200ms for 200x200 in Java, simulated annealing with Caughy distribution takes 1-3s on the same machine but maybe I don't pick up best parameters).

P.S. In English Wikipedia in Pascal solution there is error in initializing array b.

P.P.S. And solution you have tried have one more error - there is no declaration of variable x.

  • 14 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    What is the error in initializing array b?
    • 14 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it
      Array b is declared as:
          b : array[ 2 .. 16] of boolean;

      But it is filled in this way:
      for i := 1 to 8 do b[  i] := true;

      Should be:
      for i := 2 to 16 do b[  i] := true;

      Use original sources - they are always better, in Niklaus Wirth's book there are no such errors. ;)