English/italian blog

Hi everyone!

Until now, every post was made of two parts, one in Italian, one in English: in this way, they could be confusing.

Now, there are two different blogs: this one, completely in English, and the other one, completely in Italian!

On the menu at the top of the page, you can find a button to switch between the two.

Stay tuned!


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!