PROGRAMAS NICE TUTORIAL
joke.
laugh :- joke.
laugh :- joke.
joke.
hear_joke :- joke, not deaf.
understand_joke :- hear_joke, not stupid.
laugh :- understand_joke.
laugh :- stupid, not joke.
corrida
PROGRAMA 4 NICE TUTORIAL
parent(john, james).
parent(james, bill).
grandparent(john, bill) :- parent(john, james), parent(james, bill).
parent(john, james).
parent(james, bill).
grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
parent(william, john).
parent(john, james).
parent(james, bill).
parent(sue, bill).
parent(james, carol).
parent(sue, carol).
male(john).
male(james).
female(sue).
male(bill).
female(carol).
grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
father(X, Y) :- parent(X, Y), male(X).
mother(X, Y) :- parent(X, Y), female(X).
brother(X, Y) :- parent(P, X), parent(P, Y), male(X), X != Y.
sister(X, Y) :- parent(P, X), parent(P, Y), female(X), X != Y.
person(X) :- parent(X, _).
person(X) :- parent(_, X).
corrida
PROGRAMA 5 NICE TUTORIAL
emp("Jones", 30000, 35, "Accounting").
emp("Miller", 38000, 29, "Marketing").
emp("Koch", 2000000, 24, "IT").
emp("Nguyen", 35000, 42, "Marketing").
emp("Gruber", 32000, 39, "IT").
dept("IT", "Atlanta").
dept("Marketing", "New York").
dept("Accounting", "Los Angeles").
q1(Ename, Esalary, Dlocation) :- emp(Ename, Esalary, _, D), dept(D, Dlocation),
Esalary > 31000.
corrida
PROGRAMA 6 NICE TUTORIAL
cross :- not train_approaching.
cross :- -train_approaching.
cross :- not train_approaching.
-train_approaching.
cross.
-cross.
corrida
PROGRAMA 7 NICE TUTORIAL
left_arm_broken :- not right_arm_broken.
right_arm_broken :- not left_arm_broken.
can_write :- left_arm_broken.
be_angry :- can_write.
:- male(X), female(X).
corrida
PROGRAMA 8 NICE TUTORIAL
node(minnesota).
node(wisconsin).
node(illinois).
node(iowa).
node(indiana).
node(michigan).
node(ohio).
arc(minnesota, wisconsin).
arc(illinois, iowa).
arc(illinois, michigan).
arc(illinois, wisconsin).
arc(illinois, indiana).
arc(indiana, ohio).
arc(michigan, indiana).
arc(michigan, ohio).
arc(michigan, wisconsin).
arc(minnesota, iowa).
arc(wisconsin, iowa).
arc(minnesota, michigan).
% guess coloring
col(Country, red) v col(Country, green) v col(Country, blue) :- node(Country).
% check coloring
:- arc(Country1, Country2),
col(Country1, CommonColor), col(Country2, CommonColor).
corrida
PROGRAMA 9 NICE TUTORIAL
% guess horizontal position for each row
q(X,1) v q(X,2) v q(X,3) v q(X,4) v q(X,5) v q(X,6) v q(X, 7) v q(X,8) :- #int(X), X > 0.
% check
% assert that each column may only contain (at most) one queen
:- q(X1,Y), q(X2,Y), X1 <> X2.
% assert that no two queens are in a diagonal from top left to bottom right
:- q(X1,Y1), q(X2,Y2), X2=X1+N, Y2=Y1+N, N > 0.
% assert that no two queens are in a diagonal from top right to bottom left
:- q(X1,Y1), q(X2,Y2), X2=X1+N, Y1=Y2+N, N > 0.
corrida
PROGRAMA 10 NICE TUTORIAL
true.
fibonacci(1, 1) :- true.
fibonacci(1, 2) :- true.
fibonacci(F, Index) :- +(F1, F2, F),
fibonacci(F1, Index1),
fibonacci(F2, Index2),
#succ(Index1, Index2),
#succ(Index2, Index).
corrida