A Sudoku Solver

This one day code project which I did while I stayed at my mom’s place for vacation.It’s a messy sudoku solver in python. It somehow uses the same algorithm I use to solve sudoku (which is defenitely not the most efficient) in my mind. It comes up with a solution everytime(although really slow).

My helpful screenshot

I made a second attempt at a sudoku solver using a Bruteforced/Backtracking algorithm with good resluts.

A brute force algorithm visits the empty cells in some order, filling in digits sequentially, or backtracking when the number is found to be not valid. Briefly, a program would solve a puzzle by placing the digit “1” in the first cell and checking if it is allowed to be there. If there are no violations (checking row, column, and box constraints) then the algorithm advances to the next cell, and places a “1” in that cell. When checking for violations, if it is discovered that the “1” is not allowed, the value is advanced to “2”. If a cell is discovered where none of the 9 digits is allowed, then the algorithm leaves that cell blank and moves back to the previous cell. The value in that cell is then incremented by one. This is repeated until the allowed value in the last (81st) cell is discovered.

The algorithm was pretty quick and it guarantetd a solution every time ,even for really sparse sudokus. The video is slow due to the large number of screen refreshes and bad coding. Oh and the program takes in sudoku puzzles in the form of an 81 character string. with 0s for blanks.



¬ Written by Atul Vinayak on 31 October 2012