diff --git a/export/Export.go b/export/Export.go new file mode 100644 index 0000000..66a0603 --- /dev/null +++ b/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 +} diff --git a/export/PrintFlatSolutions.go b/export/PrintFlatSolutions.go deleted file mode 100644 index 3ca97af..0000000 --- a/export/PrintFlatSolutions.go +++ /dev/null @@ -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) - } -} diff --git a/export/PrintHumanReadableSolutions.go b/export/PrintHumanReadableSolutions.go deleted file mode 100644 index 3ed2054..0000000 --- a/export/PrintHumanReadableSolutions.go +++ /dev/null @@ -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("╚═══════════╝") - } -} diff --git a/export/renderFlatSolutions.go b/export/renderFlatSolutions.go new file mode 100644 index 0000000..f93a4e3 --- /dev/null +++ b/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 +} diff --git a/export/renderHumanReadableSolutions.go b/export/renderHumanReadableSolutions.go new file mode 100644 index 0000000..9b13c6e --- /dev/null +++ b/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 +} diff --git a/main.go b/main.go index 4a42b41..bf71599 100644 --- a/main.go +++ b/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()) }