go-sudoku-tutorial/sudoku.go
2019-08-13 16:56:53 +01:00

31 lines
561 B
Go

package main
import (
"fmt"
"io/ioutil"
"os"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "Usage: sudoku FILENAME")
os.Exit(2)
}
filename := os.Args[1]
data, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading puzzle file: %v\n", err)
os.Exit(3)
}
grid, err := ParseGrid(data)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing grid: %v\n", err)
os.Exit(3)
}
solution, err := grid.Solve()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(3)
}
fmt.Println(solution)
}