ソースを参照

Change internal Solution storage to [][]string (Closes #24)

Sacha Ligthert 1 年間 前
コミット
647476f6d8
3 ファイル変更9 行追加15 行削除
  1. 1 1
      controller/types.go
  2. 6 12
      export/human-readable.go
  3. 2 2
      solver/stash.go

+ 1 - 1
controller/types.go

@@ -23,7 +23,7 @@ type Controller struct {
 	// 9th row of the Sudoku puzzle.
 	Row9 string
 	// Slice with all found solutions.
-	Solutions []string
+	Solutions [][]string
 	// Number of CPUs Go routines are allowed to use.
 	NumCPUs int
 	// Number of parts the search should be split into.

+ 6 - 12
export/human-readable.go

@@ -9,19 +9,13 @@ import (
 func (export *Export) PrintHumanSolutions() {
 	for solutionIndex, solution := range export.Controller.Solutions {
 		log.Printf("\nSolution #%d:", solutionIndex+1)
-		//fmt.Println(solution)
 		fmt.Println("╔═══════════╗")
-		fmt.Println("║" + solution[0:3] + "│" + solution[3:6] + "│" + solution[6:9] + "╢")
-		fmt.Println("║" + solution[10:13] + "│" + solution[13:16] + "│" + solution[16:19] + "╢")
-		fmt.Println("║" + solution[20:23] + "│" + solution[23:26] + "│" + solution[26:29] + "╢")
-		fmt.Println("╟───┼───┼───╢")
-		fmt.Println("║" + solution[30:33] + "│" + solution[33:36] + "│" + solution[36:39] + "╢")
-		fmt.Println("║" + solution[40:43] + "│" + solution[43:46] + "│" + solution[46:49] + "╢")
-		fmt.Println("║" + solution[50:53] + "│" + solution[53:56] + "│" + solution[56:59] + "╢")
-		fmt.Println("╟───┼───┼───╢")
-		fmt.Println("║" + solution[60:63] + "│" + solution[63:66] + "│" + solution[66:69] + "╢")
-		fmt.Println("║" + solution[70:73] + "│" + solution[73:76] + "│" + solution[76:79] + "╢")
-		fmt.Println("║" + solution[80:83] + "│" + solution[83:86] + "│" + solution[86:89] + "╢")
+		for rowIndex, row := range solution {
+			if rowIndex == 3 || rowIndex == 6 {
+				fmt.Println("╟───┼───┼───╢")
+			}
+			fmt.Println("║" + row[0:3] + "│" + row[3:6] + "│" + row[6:9] + "╢")
+		}
 		fmt.Println("╚═══════════╝")
 	}
 }

+ 2 - 2
solver/stash.go

@@ -5,7 +5,7 @@ import (
 )
 
 // Prepare a valid solution for storage.
-func (solver *Solver) renderCombination(row1 int, row2 int, row3 int, row4 int, row5 int, row6 int, row7 int, row8 int, row9 int) string {
+func (solver *Solver) renderCombination(row1 int, row2 int, row3 int, row4 int, row5 int, row6 int, row7 int, row8 int, row9 int) []string {
 
 	row1s := strconv.Itoa(row1)
 	row2s := strconv.Itoa(row2)
@@ -17,5 +17,5 @@ func (solver *Solver) renderCombination(row1 int, row2 int, row3 int, row4 int,
 	row8s := strconv.Itoa(row8)
 	row9s := strconv.Itoa(row9)
 
-	return row1s + "\n" + row2s + "\n" + row3s + "\n" + row4s + "\n" + row5s + "\n" + row6s + "\n" + row7s + "\n" + row8s + "\n" + row9s + "\n"
+	return []string{row1s, row2s, row3s, row4s, row5s, row6s, row7s, row8s, row9s}
 }