The easy solving of Sudoku.
I’m not one for Sudoku puzzles. It’s not because I don’t like puzzles, but no one ever explained how logical they are. I know all puzzles can be solved with logic, but they just seemed so ridiculously hard that I didn’t want to spend the time to figure out how to do it. This is the same reason I don’t try Rubix Cubes.
This last Wednesday, for my Introduction to Artificial Intelligence class, the class was given the task to write a console application in C++ to solve the Easy Sudoku puzzles. I spent a large part of the day doing this. I had figured I’d fail and try to finish it up on the day it was due, but I just kept at it, and was able to write it all in just 126 lines of code.
The application reads a comma-delineated text file broken into nine values on nine lines (like a 9×9 Sudoku grid) and loops over each value until it figures out what the proper value is. I played one on Easy this morning and figured out the three rules the Easy puzzles use. Following the normal rules of having the values 1-9 appear only once in a horizontal line, vertical line, and 3×3 box, I just wrote out loops to look up, down, and through those other boxes for each space and widdle away at the possible answers. I surprised myself, as my logic was generally correct as I wrote it.
I also spent a little time making the output look pretty (in Console terms), check it out:

I looked over it, and it seemed to be right, but if you happen to notice something wrong, let me know!
I think it’s interesting that, although C++ is an incredibly powerful language and I’m sure there are some neat things going on behind the scenes, the output reminds me most of all of the QBASIC apps I used to write and compile years and years ago.
It’s funny how ridiculous console apps look at this point in Computing history. I like that you can quickly print out values without having to design and code an interface, but at least there could be a shnazzy-looking console, with a well thought-out monospace font (that’s actually anti-aliased).
I’d suggest we’ll get there in the future, but I have a feeling bulky grey text on a black background is going to stay around for a while.