Initial commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"git.kleiax.de/homepage/libs/sudoku"
|
||||
)
|
||||
|
||||
func main() {
|
||||
solver := sudoku.Solver{}
|
||||
solver.Add(&sudoku.LastDigit{})
|
||||
solver.Add(&sudoku.NakedSingle{})
|
||||
game, err := sudoku.New(&sudoku.PuzzleBank{}, solver, openFile())
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
field := game.GetField()
|
||||
fmt.Println(field.String())
|
||||
|
||||
err = game.Solve()
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
field = game.GetField()
|
||||
fmt.Println(field.String())
|
||||
}
|
||||
|
||||
func openFile() []byte {
|
||||
file, err := os.Open("libs/sudoku/data/sudoku-exchange-puzzle-bank/easy3.txt")
|
||||
if err != nil {
|
||||
fmt.Println("Kann datei nicht öffnen")
|
||||
os.Exit(3)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
content, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
fmt.Println("Kann Daten nicht extrahieren")
|
||||
os.Exit(4)
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
Reference in New Issue
Block a user