Sudoku Solver

The other day I was getting bored like hell. So I began solving a couple of sudoku puzzles. Then I thought of writing a little script that can actually solve a sudoku .

First, I had to choose a language. At first I wanted to go with python but in the end I decided to go with JavaScript instead. This I did particularly because of the ease with which input and output can be manipulated using jQuery. Also, I can form a much better user interface using HTML.

For those of you who don’t want to know how I made it, you can download it below. Note that this script would solve a majority of sudoku but certainly not all. This is because I have only ‘taught’ the script two techniques that are used in soduku solving. First one is naked single and the other is hidden single. These techniques can solve most of the sudoku of easy and medium levels. But sometimes it may not work.

Download it here.(Mediafire). Or here (Rapidshare).

Clicking on populate will fill the grid with a sample sudoku puzzle. Clicking on solve will solve the puzzle. Note that if on clicking solve nothing happens then that means that the puzzle cannot be solved by the script. Also, if the puzzle does not have a unique solution then 2 or 3 cells may remain empty at the end.

Notes about the code:

  1. The code is quite messed up, for now. I didn’t have any plan in my when I wrote it and so it’s all messed up. I will shortly divide the code into functions and clean the code up.
  2. Also, as I said before, only 2 techniques have been employed in this script. So, it is quite possible that it may not be able to solve the sudoku you give it to.
  3. Soon, I will add more techniques and when it is finally ready, I will post it here along with the added techniques.

2 thoughts on “Sudoku Solver

  1. It would have been better if you had provided your code via github or bitbucket. Its much more preferable to browse the code and then download if I want to play with it.

    • It’s just that most people that visit this blog aren’t interested in the code. Anyway, I’ve posted the code now just for good measure. And, it’s been updated. I have decomposed the code blocks into functions and added a new technique.
      The JS
      The HTML

Leave a reply to musingsofafriend Cancel reply