Sudoku Solver in C++

I was browsing through my code files recently and stumbled across an old piece of code I wrote as a honors contract for a computer science class (C++ specifically). It is pretty simple and demonstrates recursion nicely (the primary solve function calls itself).

Use: Using this code requires several things. You must first compile the code with your favorite compiler then place the executable in the same directory as a text file (.txt) containing a puzzle. The code will read the puzzle from the text file and then output the solution to a separate file as well as display the puzzle and solution in the terminal. Note that you do not need to have an empty text file for the solution as the code will create one.

Download: Click here.

Use Example: The .zip file you download from this page will contain the .cpp file and an example puzzle in a text file called “Input.txt” (see this text file for input puzzle format). To run the code on the example puzzle, do the following:

1. Compile the .cpp file with your favorite compiler. For this example I will assume that the name of the executable is “main”. Note that using a gcc compiler without specifying an output name will generate an executable called “a.out”.
2. Place the executable (“main”) in the directory with the “Input.txt” file if the compiler does not automatically do so.
3. Navigate to the directory containing the executable (“main”) and “Input.txt” using a terminal.
4. Type: ./main Input.txt Output.txt. (Note that you may call the output file whatever you would like).
5. You should see the given puzzle and solution in the terminal and find a new file called “Output.txt” in the same directory as the other files also containing the solution.