0315b1dd61d48c292f80a2dfd5f31aad71458fe8
1 <form action
="?" method
="POST">
2 <textarea rows
="9" cols
="9" name
="sudokupost">43 6 5 89
11 <br
/><input type
="submit" value
="Vyresit">
18 function sudoku_print ($sudo) {
19 $sudo = str_replace(" ", ".", implode("\n", $sudo) );
20 $sudo = explode("\n", $sudo);
28 function sudoku_pos ($sudo, $x, $y) {
29 return($sudo[$x-1][$y-1]);
32 function sudoku_row ($sudo, $y) {
34 foreach ($sudo as $line) {
35 $row = ($row.$line[$y-1]);
40 function sudoku_line ($sudo, $x) {
44 function sudoku_square ($sudo, $x, $y) {
45 if ( $x == 1 ||
$x == 2 ||
$x == 3 ) { $x = 1; }
46 if ( $x == 4 ||
$x == 5 ||
$x == 6 ) { $x = 4; }
47 if ( $x == 7 ||
$x == 8 ||
$x == 9 ) { $x = 7; }
48 if ( $y == 1 ||
$y == 2 ||
$y == 3 ) { $y = 1; }
49 if ( $y == 4 ||
$y == 5 ||
$y == 6 ) { $y = 4; }
50 if ( $y == 7 ||
$y == 8 ||
$y == 9 ) { $y = 7; }
62 $square = $square.$sudo[$x][$y];
75 function sudoku_candidates ($sudo, $x, $y) {
77 $donenums = ( sudoku_line($sudo, $x).sudoku_row($sudo, $y).sudoku_square($sudo, $x, $y) );
80 //foreach ( $donenums as $del ) {
81 $indx = strlen($donenums)-1;
83 $del = $donenums[$indx];
85 $cands = str_replace($del, "", $cands);
93 function sudoku_compute($sudoku) {
96 while( $sudoku_old != $sudoku ) {
97 $sudoku_old = $sudoku;
99 $is = sizeof($sudoku)-1;
101 $line = $sudoku[$is];
103 $i = strlen($line)-1;
107 $cands = sudoku_candidates ( $sudoku, ($is+
1), ($i+
1) );
108 if ( strlen($cands) == 1 && !is_numeric($sudoku[$is][$i]) ) {
109 $sudoku[$is][$i] = $cands;
122 ///CODE///////////////////////////////////////////
137 sudoku
= explode ("\n",$_POST["sudokupost"]);
141 sudoku_print($sudoku);
142 echo("\nVysledek:\n");
143 sudoku_print(sudoku_compute($sudoku));
This page took 2.171198 seconds and 5 git commands to generate.