예제 #1
0
파일: main.go 프로젝트: MarcGrol/sodoku
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)
}
예제 #2
0
파일: handlers.go 프로젝트: MarcGrol/sodoku
func (sh SodokuHandler) get(w http.ResponseWriter, r *http.Request) {

	game, err := solver.LoadString(hardExample)
	if err != nil {
		writeError(w, http.StatusBadRequest, err)
	}
	sh.doSolve(w, r, game)
}