Sudoku

I’ve been playing Sudoku on Google+. i’ve more or less mastered the easy and medium levels, but it takes me about 30 minutes to do a hard level, and I haven’t tried expert yet. Sudoku is a fairly dumb game in some ways; as a colleague of mine pointed out, it’s trivial to write a computer program which will win every time. But I find the game somewhat interesting because it mirrors, in reverse, the way I think about programming.

You can write a computer program more or less any way you like. So I tend to think of a program in terms of constraints. Typical constraints are: the desired behaviour; the available runtime; the algorithmic complexity; the available libraries; the language; maintainability; who is going to review the code and what they will accept. Write a program is a matter of finding the simplest solution which meets the constraints. Difficult programming problems are ones where the constraints come into conflict, and it’s hard to see your way through.

Sudoku works the same way, only in reverse. In programming you are allowed to write any code that meets the constraints. In Sudoku you know that there is only one solution, so you have to look for moves that are forced by the constraints. Solving a Sudoku puzzle is a matter of looking deeper and deeper into the problem until you have eliminated all moves but one.

My hope is that practice in this area will subconsciously encourage me to look deeper for constraints when writing code, which will save time in the long run because I will have to throw away less code. I doubt this will actually work, but it seems worth a try.

Also Sudoku is a good way to exercise short term memory, as I’m avoiding writing anything down while solving the puzzle. I used to play cards regularly (bridge, whist) and I was able to remember the location of many of the cards in other people’s hands. I noticed that I lost that facility as I’ve failed to practice it. As i write this I realize that short term memory is not too important in today’s world, but at least it makes me feel smarter.


Posted

in

by

Tags:

Comments

4 responses to “Sudoku”

  1. Arnaud Diederen Avatar
    Arnaud Diederen

    Ian,

    a few years ago, I found myself stuck for a couple weeks in a bed in a foreign country, of which I didn’t know (any of)the language(s).

    The only companions I had were
    – The first volume of https://secure.wikimedia.org/wikipedia/en/wiki/In_Search_of_Lost_Time , and
    – my mobile phone’s sudoku.

    The former was a breath of fresh air, thanks to Mr Proust’s extraordinary writing.
    But even the biggest book has en ending, and the only thing left was sudoku (and some stupid “snake” game thingy, but .. heh).

    It took up pretty quick, and after only a few days I realized that I started making “abstractions” emerge; pretty much like when I started programming: I took a very pragmatic approach to it, and walked my way up the ladder of abstractions.

    All in all, I can relate pretty well to the experience you describe here.
    .. though I do think short term memory is important.

    (Note: I didn’t play G+’s sudoku, but unless it’s explicitely branded as sudok_o_, I think what you meant is sudok_u_)

  2. Ian Lance Taylor Avatar

    Thanks for the comment. You’re quite right about the misspelling. Whoops. I edited the post.

  3. pixelbeat Avatar

    Wow I consider a good short term memory very useful for productive programming. When I’m in “the zone” I’m juggling lots of bits of info at once.

Leave a Reply