Sudoku Solver

Hi guys!

Today I want to show you a sudoku solver I just wrote in C++. It is a software pretty simple, but that helps you to exercise using of the language.

Note: it can solve only simple sudoku

The idea is simple: for every cell, the software considers all the possibilities, from 1 to 9. Then, for every cell, it discards the impossible alternative: and so on, processing every cell, until the puzzle is solved.

The software takes input from the text file ‘sudoku.txt’, that contains the sudoku formatted as shown in the following picture:


Every cell is separated by each other by a comma, every row by a new line;

x’s represent empty cells that the software will fill.

This software is really fast: it solved every sudoku I gave as input in less than one second.

The code should be easy to read. In the main() function, while reading the input file, there is an instruction inserted under the directive #ifdef _WIN32. When you use Windows, in fact, “new line” is achieved with the couple CRLF (that is ‘\r\n’), while on Unix with the only ‘\n’. This instruction removes the character ‘\r’, so the software can go on.

Stay tuned!



Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:


Stai commentando usando il tuo account Chiudi sessione /  Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )


Connessione a %s...