Posted By

gdonald on 09/27/06


Tagged

sudoku solver


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

mzim
skywalker
digiloper
Nahit


PHP sudoku solver


 / Published in: PHP
 

  1. #!/usr/bin/php
  2. <?php
  3.  
  4. for ($x=1;$x < 10; $x++) {
  5. for ($y=1;$y < 10; $y++) {
  6. for ($z=1;$z < 10; $z++) {
  7. if (($x + $y + $z == 15) && (($x != $y) && ($x != $z) && ($y != $z))) {
  8.  
  9. for ($a=1;$a < 10; $a++)
  10. for ($b=1;$b < 10; $b++)
  11. for ($c=1;$c < 10; $c++)
  12. if (($a + $b + $c == 15) && (($a != $b) && ($a != $c) && ($b != $c)))
  13. for ($i=1;$i < 10; $i++)
  14. for ($o=1;$o < 10; $o++)
  15. for ($p=1;$p < 10; $p++)
  16. if (($i + $o + $p == 15) && (($i != $o) && ($i != $p) && ($o != $p)))
  17. if (($x + $a + $i == 15) && (($x != $a) && ($x != $i) && ($a != $i)))
  18. if (($y + $b + $o == 15) && (($y != $b) && ($y != $o) && ($b != $o)))
  19. if (($z + $c + $p == 15) && (($z != $c) && ($z != $p) && ($c != $p)))
  20. if (($x != $b) && ($x != $c) && ($x != $o) && ($x != $p))
  21. if (($y != $a) && ($y != $i) && ($y != $c) && ($y != $p))
  22. if (($z != $b) && ($z != $a) && ($z != $o) && ($z != $i)) {
  23. echo "$x $y $z\n";
  24. echo "$a $b $c\n";
  25. echo "$i $o $p\n\n";
  26. flush();
  27. //return;
  28. }
  29. }
  30. }
  31. }
  32. }
  33.  
  34. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: phil on June 6, 2009

There are a lot of nested loops in there and I cant see how this would solve problems other than generate a solved grid - If your looking for an open-souce PHP sudoku solver you could try

http://www.idontplaydarts.com/code/sudoku-solver/

You need to login to post a comment.