Open mchirico opened 3 years ago
mchirico, Thanks for opening this issue!
oof
package nqueens
import "fmt"
//true if it is safe
func Safe(board[][] int, row int, col int)bool{
var x,y int = 0,0
for (x = 0; x < col; x++) {
if (board[row][x] == 1)
return false;
for (x = row, y = col; x >= 0 && y >= 0; x--, y--)
if board[x][y] == 1
return false;
for (x = row, y = col; y >= 0 && x < 4; x++, y--)
if board[x][y] == 1
return false;
}
}
func Solve(board[][]int, col int){
}
Great... but, maybe valid Go with tests?
func Safe(board [][]int, row int, col int) bool {
var x, y int = 0, 0
for x := 0; x < col; x++ {
if board[row][x] == 1 {
return false
}
}
for x, y := row, col; x >= 0 && y >= 0; x, y = x-1, y-1 {
if board[x][y] == 1 {
return false
}
...
Note above for x, y := row, col; x >= 0 && y >= 0; x, y = x-1, y-1
. Go doesn't support multiple x--,y--
in for loop.
Work on Queen's ... End Jan 18th