Esempio n. 1
0
func main() {
	filename := processArgs()

	gameData, err := readInput(filename)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error reading game-data from stdin: %s", err)
		os.Exit(-2)
	}

	game, err := solver.LoadString(string(gameData))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error loading game: %s", err)
		os.Exit(-2)
	}

	solutions, err := solver.Solve(game, *_Timeout, *_MinSolutions)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error solving game: %s", err)
		game.DumpGameState()
		os.Exit(-3)
	}

	for _, solution := range solutions {
		fmt.Fprintf(os.Stdout, "%s\n", solution.Dump())
		fmt.Fprintf(os.Stderr, "steps:%d, guesses:%d\n\n",
			solution.CellsToBeSolved, solution.GuessCount)
	}

	os.Exit(0)
}
Esempio n. 2
0
func (sh SodokuHandler) doSolve(w http.ResponseWriter, r *http.Request, gameToSolve *solver.Game) {
	coreSolutions, err := solver.Solve(gameToSolve, sh.Timeout, sh.MinSolutions)
	if err != nil {
		writeError(w, http.StatusInternalServerError, err)
	}

	resp := response{Error: nil}
	for _, coreSolution := range coreSolutions {
		solution := game{
			Board: boardFromSteps(coreSolution.Steps),
			Steps: fromCoreSteps(coreSolution.Steps),
		}
		resp.Solutions = append(resp.Solutions, solution)
	}
	writeSuccess(w, resp)
}