Skip to content

Instantly share code, notes, and snippets.

@nticaric
Created February 5, 2018 23:24
Show Gist options
  • Save nticaric/1710dc4ff19eb0655f07c294e0f32f4d to your computer and use it in GitHub Desktop.
Save nticaric/1710dc4ff19eb0655f07c294e0f32f4d to your computer and use it in GitHub Desktop.
func backtrack(board *[9][9]int) bool {
if !hasEmptyCell(board) {
return true
}
for i := 0; i < 9; i++ {
for j := 0; j < 9; j++ {
if board[i][j] == 0 {
for candidate := 9; candidate >= 1; candidate-- {
board[i][j] = candidate
if isBoardValid(board) {
if backtrack(board) {
return true
}
board[i][j] = 0
} else {
board[i][j] = 0
}
}
return false
}
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment