[Constraint] Logic Programming TD Exercises
created 24 february 2003,
last version 11 March 2009
A seven page list of exercises is distributed on the first day of TD:
it is available in pdf
and other formats (see library). Please always bring this list with you!
Some .pl files are available from ~gloess/chip/clp/exercises
directory: these include init.pl, map.pl, money.pl et revapp.pl. You may want to copy
them into your own chip directory.
Solutions to these exercises are available (in part) from ~gloess/chip/clp/solutions:
reading permission will be granted to students according to class progress.
These are:
-
champions.pl
solves the gold medal problem using CLP(FD);
-
coloring.pl solves
the 4 color coloring problem for any map whose topology is given by an
adjacency relation (generalizes "map.pl");
-
compiler.pl utilizes
the metamorphosis grammar technique (invented by Alain Colmerauer) to compile
algebraïc expressions into LISP forms;
-
criver.pl provides
a CLP(FD) solution to the "farmer, goat, wolf and coli-flower" problem;
-
findall.pl defines
"findall_once", a variant of CHIP findall builtin predicate, that delivers
a set of solutions, instead of a multiset;
-
init.pl generalizes
1+...+N natural number sum (see course "sumto" predicate) to rational numbers;
-
lists.pl defines
classical list manipulation predicates, using pure Prolog;
-
map.pl provides a CLP(FD)
solution and a pure Prolog solution to the Yugoslavia map coloring problem;
- money.pl solves the
"SEND+MORE=MONEY" puzzle using CLP(FD);
- money.old.pl older version of money.pl
using CLP(FD), redefining a variant of "alldifferent" and "labeling"
builtin predicates from "#\=" end "indomain" more basic constructions;
- 8queens.pl solves
the 8 queen problem using CLP(FD);
- nqueens.pl solves
the N queen problem using CLP(FD);
- nqueensC.pl solves
the N queen problem using CLP(FD), using a clever solution found in CHIP manuals;
-
nth.pl defines the "nth"
predicate, an equivalent of CHIP "element" finite domain builtin predicate:
"nth" works in the tree domain;
-
river.pl deals with
the "farmer, goat, wolf and coli-flower" problem, and provides:
-
a semantically correct and complete, but non effective (cannot run under
current Prolog systems), solution;
-
various means of achieving termination by getting around standard Prolog
strategy, while sticking to pure Prolog;
-
spriver.pl deals
with the same problem, using Prolog standard, by throwing little stones
like "le petit Poucet" to avoid cycling, which yields a very efficient
solution, like criver.pl;
-
trimming.pl defines
the "trim" the trim relation between a multiset and a set, and the remove
predicate (elimination of the first occurrence of some element from a list).