Skip to content

Commit 7fbd8fd

Browse files
committed
sudoku
1 parent 13da40b commit 7fbd8fd

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

PhpCodes/DataStructureAndAlgorithm/Sort/CompareSort/SelectSort/HeapSort.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* 堆排序
55
* 我们使用数组构建堆,注意数组下标从1开始。
66
*/
7+
78
abstract class Heap
89
{
910
protected $heap = [0];

PhpCodes/Sudoku/Sudoku.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* code-segment
4+
*
5+
* @author liu hao<[email protected]>
6+
* @copyright liu hao<[email protected]>
7+
*/
8+
9+
class Sudoku
10+
{
11+
public function run()
12+
{
13+
$sudo = [];
14+
15+
for ($i = 0; $i < 9; $i++) {
16+
for ($j = 0; $j < 9; $j++) {
17+
$tmp = 0;
18+
for ($z = 1; $z <= 9; $z++) {
19+
$flag = true;
20+
for ($a = 0; $a <= $i; $a++) {
21+
for ($b = 0; $b <= $j; $b++) {
22+
if ($a != $i && $b != $j) {
23+
if ($sudo[$a][$b] == $z) {
24+
$flag = false;
25+
break 2;
26+
}
27+
}
28+
}
29+
}
30+
if ($flag) {
31+
break;
32+
} else {
33+
continue;
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)