The brute force algorithm is "dumb" method of solving a sudoku puzzle: it sequentially tries a potential solution for an unsolved cell and then moves onto the next and attempts to find a solution for that cell, and upon finding one will move onto the next and if a solution is not found, it steps back to the previous solved cell, selects a new solution and moves onto the next again. By doing this over and over, it can be guaranteed to find a solution for any valid sudoku puzzle. However, this can be time consuming with some of the more complex puzzles taking several minutes to solve.
I have written a C# application which implements the brute-force algorithm to solve Sudoku puzzles. It's written using .Net 3.5 in Visual Studio 2008, and offers two different implementations of the brute-force algorithm - one uses arrays to hold data and the other using Linq to manipulate classes which hold data. Practically, they both use the same algorithm, just different methods of implementation. From my limited testing, they both take the same time to produce a solution for any grid; the inclusion of both was just me trying different technologies.
The app is pictured below and comes with fifty examples and allows one to add and save sudoku grids, and modify existing ones. To view an animated gif of the brute in action click here.
It's straight forwards to use and is controlled through the toolbar, whose functions left to right, are as follows:
- New sudoku
- Load a saved sudoku
- Save an existing sudoku
- Solved the current sudoku
- Reload the current sudoku
- Stop a solution attempt
- Display screen updates - selecting yes will display the solution process in real time. Selecting this option will slow down the solution process.
In addition, there are two radio buttons allowing one to select the solution class - either a Linq or array based method.
To download the executable and sample solutions, click here.
Use the above code at your own risk, and I accept no liability for any harm that may come to their computer.
I always enjoy feedback, so if you have any comments or suggestions, please leave a comment below