Skip navigation

Tag Archives: c#

So the other day, I was bored outta  my mind. I was playing sudoku on my ipod. I said to myself, like I usually do, there has got to be a better way to solve a sudoku puzzle. Then an LED light bulb(to conserve energy) lit up in my head, I will write a program to do it. Here we are. The repo is up on github.

It solves by:

  1. going through the puzzle.
  2. if it is an empty cell,  it checks corresponding row, column and block while eliminating possibilities.
  3. if it is an occupied cell, it checks neighboring rows and columns. it looks for cells with same value and see if there is an empty cell in neighboring blocks that can hold that value.
  4. it goes through these until the puzzle is solved or if we don’t solve a single cell in 5 consecutive run.
  5. if it’s not solved at this point, we use backtracking(highly inefficient but works to some degree).
  • it works by bascailly going through all the possible values.
  • guessing one cell and base the guess of the next cell on the previous one.
  • if we have no possible guesses, we go back one cell and guess again.
  • repeat this until we have successfully guess all the remaining cells.

    To-do:

    • find a better way to solve it