Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя mkagenius

Автор mkagenius, 13 лет назад, По-английски
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. :)

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

13 лет назад, # |
Rev. 7   Проголосовать: нравится +1 Проголосовать: не нравится

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.

  • 13 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    What is the error in initializing array b?
    • 13 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится
      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. ;)