-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
42 lines (38 loc) · 1.54 KB
/
main.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
35
36
37
38
39
40
41
42
package main
import "fmt"
// Taken from https://github.com/xboard/sudoku_solver
var games = []string{
"85...24..72......9..4.........1.7..23.5...9...4...........8..7..17..........36.4.",
"..53.....8......2..7..1.5..4....53...1..7...6..32...8..6.5....9..4....3......97..",
"12..4......5.69.1...9...5.........7.7...52.9..3......2.9.6...5.4..9..8.1..3...9.4",
"...57..3.1......2.7...234......8...4..7..4...49....6.5.42...3.....7..9....18.....",
"7..1523........92....3.....1....47.8.......6............9...5.6.4.9.7...8....6.1.",
"1....7.9..3..2...8..96..5....53..9...1..8...26....4...3......1..4......7..7...3..",
"1...34.8....8..5....4.6..21.18......3..1.2..6......81.52..7.9....6..9....9.64...2",
"...92......68.3...19..7...623..4.1....1...7....8.3..297...8..91...5.72......64...",
".6.5.4.3.1...9...8.........9...5...6.4.6.2.7.7...4...5.........4...8...1.5.2.3.4.",
"7.....4...2..7..8...3..8.799..5..3...6..2..9...1.97..6...3..9...3..4..6...9..1.35",
"....7..2.8.......6.1.2.5...9.54....8.........3....85.1...3.2.8.4.......9.7..6....",
// The hardest example from http://norvig.com/sudoku.html
".....5.8....6.1.43..........1.5........1.6...3.......553.....61........4........."}
func decodeGame(game string) (result [][]int) {
result = make([][]int, 9)
for r := 0; r < 9; r++ {
result[r] = make([]int, 9)
for c := 0; c < 9; c++ {
ch := game[r*9+c]
if ch == '.' {
result[r][c] = 0
} else {
result[r][c] = int(ch - '0')
}
}
}
return
}
func main() {
for i := range games {
solveSudoku(decodeGame(games[i]))
fmt.Println()
}
}