/
solver.go
40 lines (29 loc) · 873 Bytes
/
solver.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
package solver
import (
"fmt"
"github.com/DamienDuv/godoku_solver/models"
)
const limit = 50
func Solve(g *models.Grid) {
i := 0
performedAction := true
for performedAction && i < limit{
fmt.Println(i+1, " ===============================")
performedAction = false
performedAction = performedAction || nakedSingles(g)
g.UpdateDigitsPositionMask()
performedAction = performedAction || hiddenSingle(g)
if g.IsFilled() && g.IsValid() {
fmt.Printf("Solved in %d iterations\n", i+1)
return
}
performedAction = performedAction || pointingPairs(g)
performedAction = performedAction || boxLineReduction(g)
for j := 2; j <= 4; j++ {
performedAction = performedAction || nakedSubSet(g, j)
performedAction = performedAction || hiddenSubSet(g, j)
}
i++
}
fmt.Printf("Couldn't solve the grid any further with current settings\n")
}