/
working.go
63 lines (54 loc) · 1.23 KB
/
working.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package solver
import "github.com/chrismar035/sudoku-solver/grid"
type working [81]square
type workingSet struct {
Square square
Index int
}
func processSquare(i int, working working) working {
square := working[i]
square.checkValues(grid.IndicesForRow(i), working)
square.checkValues(grid.IndicesForColumn(i), working)
square.checkValues(grid.IndicesForSub(i), working)
if working[i].Value != square.Value {
working[i] = square
for _, index := range grid.IndicesForRow(i) {
if working[index].Value == 0 {
working = processSquare(index, working)
}
}
for _, index := range grid.IndicesForColumn(i) {
if working[index].Value == 0 {
working = processSquare(index, working)
}
}
for _, index := range grid.IndicesForSub(i) {
if working[index].Value == 0 {
working = processSquare(index, working)
}
}
}
return working
}
func workingFromGrid(p Grid) working {
var working working
for i, value := range p {
working[i] = newSquare(value)
}
return working
}
func (w working) blankCount() int {
count := 0
for _, square := range w {
if square.Value == 0 {
count++
}
}
return count
}
func (w working) ToGrid() (grid Grid) {
for i, square := range w {
grid[i] = square.Value
}
return
}