Wednesday, January 25, 2006

Kopying Kareem

IBM's Kareem Yusuf has a good piece on his blog this week. He's talking about the need to engage "small" developers and those testing the waters. It's a good point and I'm glad our leaders are continuing to focus in this area.

However, I was also taken by his Sudoku challenge.

I decided to take up the challenge. Having never used Eclipse's GUI builder before, I figured it would be an excuse to try it. I figured that if he's looking at Python, I'll take the Java route.

Writing the solver itself was depressingly trivial. I had all sorts of ideas in advance of how to optimise the problem (e.g. teaching the system strategies and heuristics, etc). However, I wanted, first, to get something working. So I wrote a trivial recursion. I expected some of the harder examples to take some time. Embarrassingly, no matter what I threw at it, I couldn't make it take more than a few tens of milliseconds.

Oh well.... I guess it proves, if more proof were needed, that premature optimisation is never a good idea.

Once this was done, I could bolt on a GUI. I was surprised by how nice the Eclipse GUI tooling was. But I discovered a nasty with SWT.... it doesn't let you do UI stuff on anything other than the main thread. I had plans for a clever solution where the solver ran in a separate thread and called back to the GUI to show the recursion in real time. No such luck.... I was being a little *too* naive with my implementation there.... more care would be needed. (It *is* possible to do what I want but requires a little more sophistication)

Of course, I've now ruined the magic of Sudoku for myself... but it was probably worth it for an excuse to do some coding for a change.

No comments: