Duration | Topic |
---|---|
2 weeks | Propositional & First Order Logic |
5 weeks | Logic Programming: the Prolog programming language |
5 weeks | CLPFD: Constraint Logic Programming on Finite Domains |
2 weeks | Description Logics for Semantic Web |
has_gp(GC, GP) :-
has_p(GC, P),
has_p(P, GP).
% GC has grandparent GP if
% GC has parent P and
% P has parent GP.
1+1
is a tree structure,
not evaluated to 2 by default
countdown(Ints, T, Expr) :- % Expr is a solution of the task with ints Ints and target T
subseq(Ints, Ints1, _), % if Ints has a subsequence Ints1
permutation(Ints1, Ints2), % & Ints1 has a permutation Ints2
expr_leaves(Expr, Ints2), % & Expr is a formula with list of leaves Ints2
Expr =:= T. % & Expr evaluates to T.
expr_leaves(Expr, Ints) :- % Expr is a valid formula with list of leaves Ints
append(LInts, RInts, Ints), % if Ints is the concatenation of LInts and RInts
LInts \== [], RInts \== [], % & neither of these is an empty list
expr_leaves(LExpr, LInts), % & LExpr is a formula with leaves LInts
expr_leaves(RExpr, RInts), % & RExpr is a formula with leaves RInts
build_expr(LExpr, RExpr, Expr).% & combining LExpr and RExpr may yield Expr.
expr_leaves(Int, [Int]) :- % Int is a valid formula with list of leaves [Int]
integer(Int). % if Int is an integer.
build_expr(X, Y, X+Y). % combining exprs X and Y may yield X+Y.
build_expr(X, Y, X*Y). % combining exprs X and Y may yield X*Y.
build_expr(X, Y, X-Y) :- X > Y. % combining exprs X and Y may yield X-Y if X > Y.
build_expr(X, Y, X/Y) :- % combining exprs X and Y may yield X/Y
X mod Y =:= 0. % if X divided by Y gives a 0 remainder.
| ?- countdown([75,7,9,3,3,9], 852, Expr).
Expr = (75-(7-3))*(3+9) ? ; ...
→
domain([A,R,T], 0, 9), % A, R and T are digits
A #> 0, R #> 0, % A and R can not be 0
all_distinct([A,R,T]), % A, R and T are all different
(10*A + T) + (100*R + 10*A + T) #= (100*A + 10*R + T).
→
R = 8, A = 9, T = 0