By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,733 Members | 854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,733 IT Pros & Developers. It's quick & easy.

8 queens problem

P: n/a
does anybody know an algorithm to solve the 8-queens-problem in PHP?
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Hi Andreas
does anybody know an algorithm to solve the 8-queens-problem in PHP?

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_execution_time', 30);

Greetings, Greg
Jul 17 '05 #2

P: n/a
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
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.