Solving “Greater Than” Sudoku with Answer Set Programming


absolute regularity

Sergii Dymchenko recently posted a blog showing how a “greater than” sudoku can be solved with constraint logic programming and ECLiPSe CLP.

Sergii’s post inspired me to do the same for answer setprogramming, with clasp/gringo. I’ve uploaded the code to github.

Brief notes on ASP (& Sudoku)

I am just getting started with answer set prolog. Here are some first impressions:

Syntactically, it is very similar to Good Old Fashioned Prolog, with one or two additions. For example:

syntactic sugar

There’s a lot of sugar enabling concise code. e.g.,

number(1..9).

expands to


number(1).
number(2).
number(3).
number(4).
number(5).
number(6).
number(7).
number(8).
number(9).

headless predicates

A predicate without a head is known as a constraint. The sense is that the specified conjunction is not true.


:- paint(R, C1, N), paint(R, C2, N), C1 != C2.

In the sudoku code, paint/3 is a fact signifying that a cell at Row and…

View original post 540 more words