Created
February 5, 2018 23:20
-
-
Save nticaric/b7fb2acb192073432139024bf8feb834 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 isBoardValid(board *[9][9]int) bool { | |
//check duplicates by row | |
for row := 0; row < 9; row++ { | |
counter := [10]int{} | |
for col := 0; col < 9; col++ { | |
counter[board[row][col]]++ | |
} | |
if hasDuplicates(counter) { | |
return false | |
} | |
} | |
//check duplicates by column | |
for row := 0; row < 9; row++ { | |
counter := [10]int{} | |
for col := 0; col < 9; col++ { | |
counter[board[col][row]]++ | |
} | |
if hasDuplicates(counter) { | |
return false | |
} | |
} | |
//check 3x3 section | |
for i := 0; i < 9; i += 3 { | |
for j := 0; j < 9; j += 3 { | |
counter := [10]int{} | |
for row := i; row < i+3; row++ { | |
for col := j; col < j+3; col++ { | |
counter[board[row][col]]++ | |
} | |
if hasDuplicates(counter) { | |
return false | |
} | |
} | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment