Untitled

unknown
plain_text
a year ago
2.4 kB
2
Indexable
package main
import (
"fmt"
"os"
)
const boardSize = 9
func main() {
boardStrings := os.Args[1:]
if len(boardStrings) != boardSize {
fmt.Println("Error")
return
}
board := make([][]rune, boardSize)
for i, s := range boardStrings {
if len(s) != boardSize {
fmt.Println("Error")
return
}
board[i] = []rune(s)
}
if !isValidSudoku(board) || !solveBoard(board) {
fmt.Println("Error")
return
}
printBoard(board)
}
func printBoard(board [][]rune) {
for _, row := range board {
for _, num := range row {
fmt.Printf("%c ", num)
}
fmt.Println()
}
}
func isValidSudoku(board [][]rune) bool {
for i := 0; i < boardSize; i++ {
if !isValidRow(board, i) || !isValidColumn(board, i) ||
        !isValidSubgrid(board, i/3*3, i%3*3) {
return false
}
}
return true
}
func isValidRow(board [][]rune, row int) bool {
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX