public async Task <bool> QuantumSolve(int[,] puzzle, SimulatorBase sim) { int size = puzzle.GetLength(0); FindEdgesAndInitialNumberConstraints( puzzle, size, out var emptySquareEdges, out var startingNumberConstraints, out var emptySquares ); var emptySquareEdgesQArray = new QArray <(long, long)>(emptySquareEdges); var startingNumberConstraintsQArray = new QArray <(long, long)>(startingNumberConstraints); var(foundSolution, solution) = await SolvePuzzle.Run(sim, emptySquares.Count, size, emptySquareEdgesQArray, startingNumberConstraintsQArray); if (foundSolution) { foreach (var(emptySquare, completion) in Enumerable.Zip(emptySquares, solution)) { puzzle[emptySquare.Row, emptySquare.Column] = (int)completion + 1; } Console.WriteLine("Solved puzzle."); } return(foundSolution); }
public async Task <bool> QuantumSolve(int[,] puzzle) { // Parse the puzzle into constraints. int size = puzzle.GetLength(0); FindEdgesAndInitialNumberConstraints( puzzle, size, out var emptySquareEdges, out var startingNumberConstraints, out var emptySquares ); var emptySquareEdgesQArray = new QArray <(long, long)>(emptySquareEdges); var startingNumberConstraintsQArray = new QArray <(long, long)>(startingNumberConstraints); // Estimate the resources required for the solution. var estimator = new ResourcesEstimator(); SolvePuzzle.Run(estimator, emptySquares.Count, size, emptySquareEdgesQArray, startingNumberConstraintsQArray).Wait(); Console.WriteLine($"The number of qubits estimated: {estimator.Data.Rows.Find("QubitCount")["Sum"]}"); // Solve the puzzle! var sim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: true); var(foundSolution, solution) = await SolvePuzzle.Run(sim, emptySquares.Count, size, emptySquareEdgesQArray, startingNumberConstraintsQArray); if (foundSolution) { foreach (var(emptySquare, completion) in Enumerable.Zip(emptySquares, solution)) { puzzle[emptySquare.Row, emptySquare.Column] = (int)completion + 1; } } return(foundSolution); }