Solving Sudoku Puzzles using F# and Microsoft Solver Foundation

I’ve been doing a bit of work with Solver Foundation lately and as I got to know the package it suddenly occurred to me Solver Foundation could be easily used to solve Sudoku puzzles. While I knew that solving Sudoku in F# wasn’t particularly an original idea, Jon Harrop has a custom Sudoku solver in F# that dates back to 2007, but I thought using Solver Foundation might be an interesting approach. I was on the train at the time so I fired up VS and pretty quickly had a working solution. A little googling later revealed that I wasn’t at all the first to have thought of this, in fact there’s event a Sudoku example packaged with Solver Foundation, but using the OML solver language rather than F#. Anyway, as I have a working solution I thought I may as well show it here. At 121 lines, including comments, inputs and solution printing functions, I don’t think it’s too bad, however I do think there’s some room to make it even shorter.

Bookmark
dotnetkicks+, digg+, reddit+, del.icio.us+, dzone+, facebook+

Print | posted @ Sunday, December 12, 2010 3:53 AM

Comments on this entry:

Gravatar # re: Solving Sudoku Puzzles using F# and Microsoft Solver Foundation
by Frank de Groot - Schouten at 12/13/2010 5:17 AM

At Microsoft PDC 2010, Bart de Smet demonstrated a LINQ provider that spews OML and invokes Solver Foundation, solving a Sudoku using LINQ in C#: http://bit.ly/bfzKCk. Unfortunately I haven't seen his code online anywhere.

Your comment:

(Note: all comments are moderated so it may take sometime to appear)

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 7 and 7 and type the answer here: