% ILP-503 (Prof. Dr. Silvio do Lago Pereira)

% ---------------------------------------------------------------------
% EXEMPLO 3
% ---------------------------------------------------------------------

fat(0, 1).   % base
fat(N, F) :- % passo
   N > 0,
   M is N-1,
   fat(M, R),
   F is R*N.

% ---------------------------------------------------------------------
% EXEMPLO 4
% ---------------------------------------------------------------------

pot(_, 0, 1).
pot(X, N, P) :-
   N > 0,
   M is N-1,
   pot(X, M, R),
   P is R*X.

% ---------------------------------------------------------------------
% EXEMPLO 6
% ---------------------------------------------------------------------

chama(a, b).
chama(a, c).
chama(a, d).
chama(c, e).
chama(c, f).
chama(f, g).

usa(X, Z) :- chama(X, Z).
usa(X, Z) :- chama(X, Y), usa(Y, Z).

% ---------------------------------------------------------------------
% EXERCICIO 8
% ---------------------------------------------------------------------

sobre(b, a). sobre(d, b).
sobre(d, c). sobre(e, d).

% ---------------------------------------------------------------------
% EXERCICIO 9
% ---------------------------------------------------------------------

via(a, b, 25). via(a, d, 23).
via(b, c, 19). via(b, e, 32).
via(c, d, 14). via(c, f, 28).
via(d, f, 30). via(e, f, 26).

% ---------------------------------------------------------------------
% EXEMPLO 8
% ---------------------------------------------------------------------

exiba([]).
exiba([X|Y]) :- writeln(X), exiba(Y).

% ---------------------------------------------------------------------
% EXEMPLO 9
% ---------------------------------------------------------------------

tam([], 0).
tam([_|Y], T) :- tam(Y, R), T is R+1.

% ---------------------------------------------------------------------
% EXEMPLO 10
% ---------------------------------------------------------------------

membro(X, [X|_]).
membro(X, [_|Y]) :- membro(X, Y).

% ---------------------------------------------------------------------
% EXEMPLO 11
% ---------------------------------------------------------------------

anexa([], B, B).
anexa([X|A], B, [X|C]) :- anexa(A, B, C).
