Compare commits
2 Commits
b83d6bdde4
...
71fefd760e
Author | SHA1 | Date | |
---|---|---|---|
71fefd760e | |||
2461f5b417 |
12
export/Export.go
Normal file
12
export/Export.go
Normal file
@ -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
|
||||||
|
}
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
export/renderFlatSolutions.go
Normal file
15
export/renderFlatSolutions.go
Normal file
@ -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
export/renderHumanReadableSolutions.go
Normal file
22
export/renderHumanReadableSolutions.go
Normal file
@ -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
|
||||||
|
}
|
@ -6,19 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validate if the char provided is 0-9
|
|
||||||
func (flags *Flags) validChar(char rune) (valid bool) {
|
|
||||||
decvals := [10]int{48, 49, 50, 51, 52, 53, 54, 55, 56, 57}
|
|
||||||
|
|
||||||
for _, value := range decvals {
|
|
||||||
if char == rune(value) {
|
|
||||||
valid = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print help information for the end-user
|
// Print help information for the end-user
|
||||||
func (flags *Flags) printUsage() {
|
func (flags *Flags) printUsage() {
|
||||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
||||||
|
14
flags/validChar.go
Normal file
14
flags/validChar.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package flags
|
||||||
|
|
||||||
|
// Validate if the char provided is 0-9
|
||||||
|
func (flags *Flags) validChar(char rune) (valid bool) {
|
||||||
|
decvals := [10]int{48, 49, 50, 51, 52, 53, 54, 55, 56, 57}
|
||||||
|
|
||||||
|
for _, value := range decvals {
|
||||||
|
if char == rune(value) {
|
||||||
|
valid = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
8
main.go
8
main.go
@ -45,12 +45,6 @@ func main() {
|
|||||||
go solver.CheckCombinations()
|
go solver.CheckCombinations()
|
||||||
solver.Tracker()
|
solver.Tracker()
|
||||||
|
|
||||||
// Print the valid solutions
|
log.Println(export.Export())
|
||||||
switch controller.Output {
|
|
||||||
case "human":
|
|
||||||
export.PrintHumanReadableSolutions()
|
|
||||||
case "flat":
|
|
||||||
export.PrintFlatSolutions()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user