Hurray, I’m not dead!
Yes, that’s right. Despite an impossibly long period of total invisibility on the interwebz, I am still here.
Basically, I have been busy with school, and all my programming stuff has been pushed down to a pretty low priority.
(By the way, free iPhones, computers, etc., might very well prevent this from happening again :)).
So, you might have noticed that I chose a new theme for this blog. It is called Abstracta, and was designed by Rob Goodlatte. I love it. Very pretty and clean.
Ok, so update time:
- I am officially a member of the MIT class of 2012! I’ll be off to Boston in the fall to meet lots of people smarter than me as I learn that I HTFP
- Almost as exciting, I have not gotten anything done on Web Importer or PhotoBook. You’ll see so many updates this summer, I swear! I have like totally nothing to do until the end of August.
- But I have done a little work on Adium. Look for live contact list searching in the next release (1.3)
And now… story time!
So, a couple of weeks ago, I finished all my AP tests (which, if you don’t know, are classes+tests high school students take in particular subject areas that are supposed to be “college level.” I took AP English Lit, AP Calculus BC, and AP Physics C). After those tests, we have very little work left to do for the last 5ish weeks of school, so my physics teacher gave us a Sudoku (probably to keep us quiet). I have never done a Sudoku before, and needless to say, I could not get the 5 star one she gave us. Frustrated, I sort of forgot about it.
Then, last weekend was Prom. All the girls, and I suppose some of the guys, felt the need to go through the predictable ritual of spending hundreds on hair and plastering themselves in makeup. I was quite bored, and instead of doing something normal like going outside or seeing a movie or something, I decided to revisit that Sudoku. Now, instead of doing something a typical antisocial sudoku player would do, like spending another hour trying to solve it, or something a self-conscious antisocial sudoku player would do, like going online and cheating to find the solution, I decided to be a self-conscious, antisocial, geeky sudoku player and write my own Sudoku solver.
Luckily, I had recently seen this xkcd comic, so I felt a bit better about myself.
And just before I left for fun pictures and such, I had a working Cocoa sudoku solver that solved the puzzle in about a quarter of a second.
I added some finishing touches this week, so I thought I might as well put it up here and release the code.
Don’t expect anything amazing or original. This just uses what is basically a brute force algorithm to solve the puzzle. And, even that algorithm is written very poorly and is quite ugly. If you are looking for a useful Sudoku solver, just search Google. There are tons of really good human logic sudoku solvers available.
But mine, of course, is better.

If you are learning Cocoa, this project demonstrates these topics:
- Interface Builder and standard controls
- Using an NSMatrix to lay out a grid of NSCells (81 Sudoku boxes)
- Using NSNumberFormatters (to ensure that only the integers 1-9 can be entered into a box)
- Basic threading with NSThread (the solving algorithm runs in the background in its own thread)
|
Download the pre-built application |
|
Download the Source Code (BSD License) |
Responses to “Antisocial Sudoku Fun”
May 24th, 2008 at 2:24 pm
Thanks! I am quite excited.
Also, I have been overwhelmed with spam comments this past week for some reason, so I added a little captcha plugin that should slow it down. In exchange for requiring everyone to type an extra word, I made the email field optional
So, this is a test comment….
Not that I would not have responded to your comment anyway, Qin Zhi Lau ![]()
October 19th, 2009 at 5:50 pm
I am new to COCOA programming and had been looking for a tutorial on how to use NSMatrix when I found your post here. Wondered if you wouldn’t mind answering a few questions.
With your SudokuSquareCell and SudokuMatrix, did you write them by hand and then somehow leverage them in Interface Builder or did you create them first in interface builder then extend them by hand.
I am assuming that you extended them in order to add the shading and number formatting am I correct?
Would you mind laying out a few short steps to guide me in recreating your GUI using the tools?
Thanks in advance

May 24th, 2008 at 1:16 am
Congrats on MIT! And thanks for PhotoBook!