Solving a Constraint Satisfaction Problem with core.logic

25 May 2014

A few days back a co-worker presented a puzzle. The puzzle was a Constraint Satisfaction Problem which I solved using core.logic. Here is the puzzle description:

In the picture below, find a solution by “configuring” each circle. Allowable configurations for each circle are the numbers 1 through 8. A couple of rules: 1) You cannot repeat any numbers, all numbers 1 through 8 must be used and 2) No two circles connected by arrows can have consecutive numbers (e.g. if the left most circle is a 4, then the circles to the right of it cannot be labeled a 3 or 5).

problem

And here is the solution:

This was my first program using core.logic and it was really fun.