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.

A simple graphing program using Processing

A little while ago I was playing with some sensors I had, and though how nice it’d be if I could graph their outputs on my computer. So I wrote a simple program in the Processing language to do just that. Although the code I wrote was able to get strings of data from my Arduino, the code I am posting here is somewhat stripped out to be as understandable as possible to beginners. Instead of displaying data from sensors, this program graphs your mouse’s x- and y-coordinates. It is still capable of plotting data from sensors, but you’ll have to write the code to fetch and handle the data. As is explained in the comments in the code, there are three variables (integers) to store incoming data points (newDataPoint1, newDataPoint2 and newDataPoint3), each of which corresponds to one of the graphs. Your data-handling code will have to feed each of these variables one new integer each iteration of the draw loop in order for this program to function properly. Currently, newDataPoint1 and newDataPoint2 are being set to the mouse’s x- and y-coordinate respectively and newDataPoint3 is just set to “0” (not being used). Thus for users with a little experience with Processing it should be quite easy to modify this code to your needs.

Here’s what it looks like (the blue line at the top is the third graph which is currently not being used):

Continuous Graph

Before you can run my code, you’ll have to download and install Processing. Once you have done that, you can download my code here (click to view, right-click and “Save As” do download).

Enjoy!