leah blogs

November 2005

17nov2005 · A Sudoku Solver in Prolog

More and more people were requesting it, so I decided to publish my Sudoku solver, written for GNU Prolog and its finite domain solver. You probably can’t easily port it to some other Prolog, but it’s very efficient, despite being completely dumb code.

However, my Prolog knowledge approaches epsilon and I think the code is rather ugly, but it works. Do with it whatever you want.

Example of use:

#1104<1|>lilith:~$ gprolog 
GNU Prolog 1.2.16
By Daniel Diaz
Copyright (C) 1999-2002 Daniel Diaz
| ?- [sudoku].
| ?- metabox(normal, L,

L = [4,2,1,9,6,7,8,5,3,6,7,5,3,1,8,4,9,2,3,8,9,2,4,5,6,1,7,1,9,8,7,
3,7,4,9,1,2,6,5,9,5,4,6,8,2,3,7,1] ? ;


Very basic and unpolished, but the valid solution. Don’t remind me of the code when you meet me. ;-)

NP: Elliott Smith—Passing Feeling

Copyright © 2004–2022