private static void Main() { var puzzle = new Puzzle(); var internalRows = InternalRowBuilder.BuildInternalRows(puzzle); var dlxMatrix = DlxMatrixBuilder.BuildDlxMatrix(puzzle, internalRows); var dlx = new Dlx(); var solution = dlx.Solve(dlxMatrix, rows => rows, row => row.Bits).FirstOrDefault(); if (solution != null) { DumpSolutionSimple(solution, dlxMatrix); Console.WriteLine(); DumpSolutionCube(puzzle, solution, dlxMatrix); } }
private void SolvePuzzleInBackground() { var internalRows = InternalRowBuilder.BuildInternalRows(_puzzle); var dlxMatrix = DlxMatrixBuilder.BuildDlxMatrix(_puzzle, internalRows); var dlx = new Dlx(_cancellationToken); dlx.SearchStep += (_, searchStepEventArgs) => InvokeActionPassingSubsetOfInternalRows( internalRows, searchStepEventArgs.RowIndexes, _onSearchStep); var firstSolution = dlx.Solve(dlxMatrix, rows => rows, row => row.Bits).FirstOrDefault(); if (firstSolution != null) { InvokeActionPassingSubsetOfInternalRows( internalRows, firstSolution.RowIndexes, _onSolutionFound); } }