func scanCage(s *domain.Sudoku) (bool, error) { rows := domain.BOARD_ROWS / 3 cols := domain.BOARD_COLS / 3 for i := 0; i < rows; i++ { for j := 0; j < cols; j++ { count := make([]int, 9) lastRow := make([]int, 9) lastCol := make([]int, 9) for row := i * 3; row < i*3+3; row++ { for col := j * 3; col < j*3+3; col++ { for n, mask := range AV_LIST { if s.Available[row*domain.BOARD_COLS+col]&mask == mask { count[n]++ lastRow[n] = row lastCol[n] = col } } } } // A hidden single in the cage has been found, solve it for j, c := range count { if c != 1 { continue } if s.Answer[lastRow[j]*domain.BOARD_COLS+lastCol[j]] != 0 { continue } fmt.Printf(" * Solving hidden single [cage]: %dx%d (%d)\n", lastCol[j], lastRow[j], j+1) if err := s.SolveCell(lastRow[j], lastCol[j], uint(j+1)); err != nil { return false, err } return true, nil } } } return false, nil }
func scanCol(s *domain.Sudoku) (bool, error) { for i := 0; i < domain.BOARD_COLS; i++ { count := make([]int, 9) lastRow := make([]int, 9) // Scan the rows for j := 0; j < domain.BOARD_ROWS; j++ { for n, mask := range AV_LIST { if s.Available[j*domain.BOARD_COLS+i]&mask == mask { count[n]++ lastRow[n] = j } } } // A hidden single in the col has been found, solve it for j, c := range count { if c != 1 { continue } if s.Answer[lastRow[j]*domain.BOARD_COLS+i] != 0 { continue } fmt.Printf(" * Solving hidden single [col]: %dx%d (%d)\n", i, lastRow[j], j+1) if err := s.SolveCell(lastRow[j], i, uint(j+1)); err != nil { return false, err } return true, nil } } return false, nil }