Evil Science A whole load of stuff


Sudoku Brute – a C# implementation of the Brute-force algorithm

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:

  1. New sudoku
  2. Load a saved sudoku
  3. Save an existing sudoku
  4. Solved the current sudoku
  5. Reload the current sudoku
  6. Stop a solution attempt
  7. 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.

To download the source files and solutions, click here. To view the source code and run it, you'll need Microsoft Visual Studio which you can find 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

Filed under: C# Leave a comment
Comments (1) Trackbacks (0)
  1. Nice app and great code! Thanks!

Leave a comment

nine + = 11

No trackbacks yet.