public void Should_Solve_Sample_05370342103181()
        {
            var result = _puzzleSolver.Solve(File.ReadAllLines("Samples\\05370342103181"));

            Assert.AreEqual(2, result.NumberOfGroups);
            Assert.AreEqual(12, result.NumberOfPiecesDisconnected);
        }
Esempio n. 2
0
        // TODO: Next is to add quality checks -> no more than x clues in box, row or column.
        // TODO: Next is to add quality checks -> no more than x clues in box, row or column.
        // TODO: Next is to add quality checks -> no more than x clues in box, row or column.
        // TODO: Next is to add quality checks -> no more than x clues in box, row or column.

        private NextStepToSolve NextStep()
        {
            NextStepToSolve rv;
            var             cluesPlaced = PuzzleToSolve.AsText(' ').Count(c => c != ' ');

            // are we over the limit?
            if (cluesPlaced <= _puzzleGeneratorOptions.GetMaximumFilledCells(PuzzleToSolve.Size))
            {
                // do we have some to add before trying to solve
                if (cluesPlaced >= _puzzleGeneratorOptions.GetMinimumFilledCells(PuzzleToSolve.Size))
                {
                    var solutions     = _puzzleSolver.Solve(PuzzleToSolve, 2);
                    var solutionCount = solutions.Count;
                    rv = solutionCount == 1
                        ? NextStepToSolve.Solved
                        : NextStepToSolve.TooFewClues;
                }
                else
                {
                    rv = NextStepToSolve.TooFewClues;
                }
            }
            else
            {
                rv = NextStepToSolve.TooManyClues;
            }

            return(rv);
        }
Esempio n. 3
0
        protected static void CreateAndSolve()
        {
            IPuzzleSolver solver = PuzzleSolverFactory.Create();
            object        answer = solver.Solve();

            Console.WriteLine($"Answer for day {solver.Day} is {answer}");
        }
        public IActionResult GetSolution(PuzzleModel puzzleModel)
        {
            var puzzle = _puzzleSolver.Solve(puzzleModel.Rows, puzzleModel.Columns, puzzleModel.HorizontalNumbers,
                                             puzzleModel.VerticalNumbers);

            return(Ok(puzzle.Desk));
        }
Esempio n. 5
0
        private static void Main(string[] args)
        {
            var filename = "05940506228403";

            if (args.Length > 0)
            {
                filename = args[0];
                Console.WriteLine(filename);
            }

            var result = PuzzleSolver.Solve(File.ReadAllLines(filename));

            Console.WriteLine($"{result.NumberOfPiecesDisconnected} Alone");
            Console.WriteLine($"{result.NumberOfGroups} Groups");
            Console.ReadKey();
        }
Esempio n. 6
0
        public IPuzzleOutput Solve()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            IPuzzleOutput solverOutput = null;

            for (int i = 0; i < runXTimes; ++i)
            {
                solverOutput = _puzzleSolver.Solve();
            }
            stopwatch.Stop();

            return(new TimedPuzzleSolverOutput(
                       output: solverOutput,
                       timeMs: stopwatch.ElapsedMilliseconds
                       ));
        }