%%%%%%%%%%%%%%%%% 1 %%%%%%%%%%%%%%%%%%%%%%% animal(duck). animal(cat). animal(dog). animal(horse). swim(duck). swim(dog). r(X):-animal(X),swim(X),!,fail. r(X):-animal(X). % explain the definition of r(X). % what are the answers for ?-r(X). % What happens if we remove ! from the first %rule? % What kind of ! uses the definition of r? %red or green? Explain. %%%%%%%%%%%%%%%% 2 %%%%%%%%%%%%%%%%%% % Use the cut fail combination in order to % define the predicate no(P) which is true if % P is false. %%%%%%%%%%%%%%%% 3 %%%%%%%%%%%%%%%% %Consider the following friendship relation: friend(radu, elena). friend(elena, mihai). friend(zoe, viorel). % define, using the cut fail combination the %relation unfriend which takes place if it %is unknown whether X and Y are friends %%%%%%%%%%%%%%%%% 4 %%%%%%%%%%%%%%%%%% % What kind of structures can be unified with % _, [_], [_,_], [_|_], [X,X|_] %%%%%%%%%%%%%%%%% 5 %%%%%%%%%%%%%%%%%%%%%% % A solution to Hanoi's tower % Move all the disks from axe_1 to axe_2 % one disk at a time, do not put a greater disk %on a smaller disk % one possible answer: hanoi(N):-move(N,axe_1,axe_2,axe_3). move(0,_,_,_):-!. move(N,A,B,C):- M is N-1, move(M,A,C,B), say(A,B), move(M,C,B,A). say(X,Y):-write([move,one,disk,from,X,to,Y]),nl. %%%%%%%%%%%%%%%% 6 %%%%%%%%%%%%%%%%%%%%%%%% %Define a database for the following: % A day of a week can be Monday, Tuesday, % Wednesday, Thursday, Friday, Saturday, Sunday. % Define relations for: % next(X,Y) Y is the next day of X % twodaysafter(X,Y) Y is the second day after X %%%%%%%%%%%%%%%%% 7 %%%%%%%%%%%%%%%%%%%%%%% % Consider the following database: grade(popescu,'LCS',9.0). grade(popescu,'FP',7.0). grade(popescu,'LP',10.0). grade(albu,'Algebra',9.0). grade(albu,'Management',8.5). % define a program general_average(Pers,Ga) % which computes the general average of the % person X. Example: % ?-general_average(popescu,Ga). % ?- Ga=8.66666 % Sugestion 1: define a predicate similar to %findall % Sugestion 2: % findall(Term,+G,-L) % computes the list L of all possible instances % of Term produced by answering to G. % findall(N,X,grade(popescu,_,N),L).