Created
February 5, 2018 23:24
-
-
Save nticaric/1710dc4ff19eb0655f07c294e0f32f4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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