8 queens problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andreas

    8 queens problem

    Hi!
    does anybody know an algorithm to solve the 8-queens-problem in PHP?
  • Gregor Favre

    #2
    Re: 8 queens problem

    Hi Andreas
    [color=blue]
    > does anybody know an algorithm to solve the 8-queens-problem in PHP?[/color]

    You may want to go with a backtracking algorithm. You may do a search on the
    net for it and find some language-independent code, which to convert to
    php-code should be almostly an easy task. I wrote something like that for
    fun in Java, you may email me directly if you want the code.

    Btw, make sure, that the maximum execution time of php scripts on your
    server is high enough. By default, script abort after 30 seconds. With 8
    queens you should get the solutions in some seconds, but if you use more
    than 8 queens, by retrieving all solutions, it may take some long time...!

    Put the line below on the top of your script, for a timeout of 30 seconds.
    Put 0 as the second parameter and it will run without any time-limit:

    ini_set('max_ex ecution_time', 30);

    Greetings, Greg


    Comment

    • Andreas

      #3
      Re: 8 queens problem

      It worked, thanks a lot! The PHP script finds all 92 solutions in
      about 0.6 seconds. How long does your Java program take?

      Greetings, Andreas

      Comment

      Working...