Exemplo n.º 1
0
        static void Main(string[] args)
        {
            foreach (var puzzle in TestPuzzles.puzzles)
            {
                var dancingLinks = new DancingLinks(puzzle);
                dancingLinks.Solve();

                // var board = new Board(puzzle);
                // var backtrack = new Backtrack(board);
                // backtrack.Solve();
            }
        }
Exemplo n.º 2
0
        public void SolveTest()
        {
            var grid = new[]
            {
                new[] { 1, 0, 3, 4 },
                new[] { 3, 4, 1, 2 },
                new[] { 2, 1, 4, 3 },
                new[] { 4, 3, 2, 1 }
            };

            var sut   = new DancingLinks();
            var xKeys = sut.BuildSetMatrixKeys(4);
            var y     = sut.BuildSubsetMatrix(4, 2, 2);
            var x     = sut.ExactCover(xKeys, y);

            sut.LoadCaseToSolve(grid, x, y);

            var solution = sut.Solve(x, y).First();

            solution.Dump(TestContext.WriteLine, $"Dumping solution, item count = {solution.Count}");
        }