mirror of
https://github.com/sigmasternchen/sudoku-solver
synced 2025-03-15 07:48:56 +00:00
minimize the number of guesses to reduce non-polynomial time component
This commit is contained in:
parent
3b59dfc374
commit
4362be5345
1 changed files with 44 additions and 32 deletions
26
main.go
26
main.go
|
@ -157,6 +157,7 @@ func eliminate(field *field) *int {
|
|||
}
|
||||
|
||||
type result int
|
||||
|
||||
const (
|
||||
unsolved result = iota
|
||||
solved
|
||||
|
@ -192,20 +193,31 @@ func copyField(fieldToCopy field) field {
|
|||
}
|
||||
|
||||
func addGuesses(field field) {
|
||||
hasGuess := false
|
||||
minX := 0
|
||||
minY := 0
|
||||
minLength := size + 1
|
||||
|
||||
for x := 0; x < size; x++ {
|
||||
for y := 0; y < size; y++ {
|
||||
if len(field[x][y]) > 1 {
|
||||
for _, value := range field[x][y] {
|
||||
length := len(field[x][y])
|
||||
if length > 1 && length < minLength {
|
||||
hasGuess = true
|
||||
minX = x
|
||||
minY = y
|
||||
minLength = length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if hasGuess {
|
||||
for _, value := range field[minX][minY] {
|
||||
newField := copyField(field)
|
||||
newField[x][y] = []int{value}
|
||||
newField[minX][minY] = []int{value}
|
||||
|
||||
atomic.AddInt64(&possibilities, 1)
|
||||
guesses <- newField
|
||||
}
|
||||
// we don't need to add more
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue