Permalink
Browse files

Also implemented hidden singles search in rows & columns

  • Loading branch information...
1 parent 117170d commit 6ed68b2fb5997aa3b04ce378444075e576ed18ab @AVBelyy committed Apr 21, 2012
Showing with 30 additions and 2 deletions.
  1. +30 −2 src/solver/solver.go
View
@@ -82,21 +82,49 @@ func (s *Solver) Solve() {
}
}
}
+ // check for hidden singles in row
+ for x := uint(0); x < 9; x++ {
+ if v&(1<<x) == 0 { continue }
+ for k := 0; k < 9; k++ {
+ if !s.matrix[i][k].final && k != j {
+ if s.matrix[i][k].value&(1<<x) != 0 {
+ goto hidden_singles_row_next
+ }
+ }
+ }
+ v, f, delta = x+1, true, true
+ goto final
+ hidden_singles_row_next:
+ }
+ // check for hidden singles in column
+ for x := uint(0); x < 9; x++ {
+ if v&(1<<x) == 0 { continue }
+ for k := 0; k < 9; k++ {
+ if !s.matrix[k][j].final && k != i {
+ if s.matrix[k][j].value&(1<<x) != 0 {
+ goto hidden_singles_column_next
+ }
+ }
+ }
+ v, f, delta = x+1, true, true
+ goto final
+ hidden_singles_column_next:
+ }
// check for hidden singles in box
for x := uint(0); x < 9; x++ {
if v&(1<<x) == 0 { continue }
for k1 := b_y; k1 < b_y+3; k1++ {
for k2 := b_x; k2 < b_x+3; k2++ {
if !s.matrix[k1][k2].final && (k1 != i || k2 != j) {
if s.matrix[k1][k2].value&(1<<x) != 0 {
- goto hidden_singles_next
+ goto hidden_singles_box_next
}
}
}
}
v, f, delta = x+1, true, true
goto final
- hidden_singles_next:
+ hidden_singles_box_next:
}
if v != v_s {
delta = true

0 comments on commit 6ed68b2

Please sign in to comment.