PHP sudoku solver


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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

You need to login to post a comment.