Jelajahi Sumber

Rework how priting of solutions are handled.

Sacha Ligthert 1 tahun lalu
induk
melakukan
71fefd760e

+ 12 - 0
export/Export.go

@@ -0,0 +1,12 @@
+package export
+
+func (export *Export) Export() (render string) {
+	// Print the valid solutions
+	switch export.Controller.Output {
+	case "human":
+		render = export.RenderHumanReadableSolutions()
+	case "flat":
+		render = export.renderFlatSolutions()
+	}
+	return
+}

+ 0 - 14
export/PrintFlatSolutions.go

@@ -1,14 +0,0 @@
-package export
-
-import (
-	"fmt"
-	"log"
-)
-
-// Print solutions into a human friendly format for in the console.
-func (export *Export) PrintFlatSolutions() {
-	for solutionIndex, solution := range export.Controller.Solutions {
-		log.Printf("\nSolution #%d:", solutionIndex+1)
-		fmt.Println(solution)
-	}
-}

+ 0 - 21
export/PrintHumanReadableSolutions.go

@@ -1,21 +0,0 @@
-package export
-
-import (
-	"fmt"
-	"log"
-)
-
-// Print solutions into a human friendly format for in the console.
-func (export *Export) PrintHumanReadableSolutions() {
-	for solutionIndex, solution := range export.Controller.Solutions {
-		log.Printf("\nSolution #%d:", solutionIndex+1)
-		fmt.Println("╔═══════════╗")
-		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("╚═══════════╝")
-	}
-}

+ 15 - 0
export/renderFlatSolutions.go

@@ -0,0 +1,15 @@
+package export
+
+import (
+	"fmt"
+	"strconv"
+)
+
+// Print solutions into a human friendly format for in the console.
+func (export *Export) renderFlatSolutions() (render string) {
+	for solutionIndex, solution := range export.Controller.Solutions {
+		render += fmt.Sprintln("\nSolution #" + strconv.Itoa(solutionIndex+1) + ":")
+		render += fmt.Sprintln(solution)
+	}
+	return
+}

+ 22 - 0
export/renderHumanReadableSolutions.go

@@ -0,0 +1,22 @@
+package export
+
+import (
+	"fmt"
+	"strconv"
+)
+
+// Print solutions into a human friendly format for in the console.
+func (export *Export) RenderHumanReadableSolutions() (render string) {
+	for solutionIndex, solution := range export.Controller.Solutions {
+		render += fmt.Sprintln("\nSolution #" + strconv.Itoa(solutionIndex+1) + ":")
+		render += fmt.Sprintln("╔═══════════╗")
+		for rowIndex, row := range solution {
+			if rowIndex == 3 || rowIndex == 6 {
+				render += fmt.Sprintln("╟───┼───┼───╢")
+			}
+			render += fmt.Sprintln("║" + row[0:3] + "│" + row[3:6] + "│" + row[6:9] + "╢")
+		}
+		render += fmt.Sprintln("╚═══════════╝")
+	}
+	return
+}

+ 1 - 7
main.go

@@ -45,12 +45,6 @@ func main() {
 	go solver.CheckCombinations()
 	solver.Tracker()
 
-	// Print the valid solutions
-	switch controller.Output {
-	case "human":
-		export.PrintHumanReadableSolutions()
-	case "flat":
-		export.PrintFlatSolutions()
-	}
+	log.Println(export.Export())
 
 }