-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsogoku.go
34 lines (28 loc) · 803 Bytes
/
sogoku.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"os"
"fmt"
"strings"
)
func main() {
// Get the board from the command line and check it.
if len(os.Args) != 2 {
fmt.Println("Please enter an 81 character string, using 0 as whitespace and working from left to right, top to bottom.")
os.Exit(1)
}
boardString := os.Args[1]
boardReader := strings.NewReader(boardString)
if boardReader.Len() != 81 {
fmt.Println("Please enter an 81 character string, using 0 as whitespace and working from left to right, top to bottom.")
os.Exit(1)
}
// Create the grid and print it once for easy error checking.
grid := NewGrid(boardString)
grid.Print()
// Update the grid while it is not yet completed.
for !grid.Completed() {
grid.Update()
}
// Print the solved grid.
grid.Print()
}