Saturday, June 03, 2006

 

OCaml and Sudoku

I've been spending my evenings learning about OCaml. As a first toy program, I wrote a sudoku solver in OCaml similar to the Ruby sudoku solver I did a few months ago.

I was pretty proud of my program, which solved sudokus in a fraction of a second. Then I ran across a 19-line OCaml sudoku solver on the Internet. Mine is 187 lines (including comments and blank lines).

I don't understand the 19-line version. It makes me feel stupid.

I take some solace from the facts that I'm a beginner, that I wrote my code for clarity rather than conciseness, and that I wrote a functional-style program, whereas the 19-line version uses some imperative features. But still, I am very concerned that I just do not understand the 19-line version, and it doesn't look that tricky.

Maybe I need to stick with C++. I guess I've become an old dog.

[UPDATE: After getting some sleep, the 19-line code made sense to me. I had to have a fresh brain to make sense of all those tightly-packed m's, n's, x's, y's and i's.]


Comments:
Glad you like my 19-line Sudoku solver in OCaml!

Cheers,
Jon Harrop.
 
Have you tried the new grid game SHENDOKU. I loved the idea of being able to play with friends instead of playing alone. Check it out at www.shendoku.com
 
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?