% ILP-503 (Prof. Dr. Silvio do Lago Pereira)

% ---------------------------------------------------------------------
% EXEMPLO 1
% ---------------------------------------------------------------------

bit(0).
bit(1).

bin([A,B]) :- bit(A), bit(B).

% ---------------------------------------------------------------------
% EXEMPLO 2
% ---------------------------------------------------------------------

fun(29, ruy).
fun(45, ivo).

dep(29, yan).
dep(29, zoe).
dep(29, ary).
dep(45, ney).

% ---------------------------------------------------------------------
% EXERCICIO 4
% ---------------------------------------------------------------------

item(a).
item(b).
item(c).

perm1([X,Y,Z]) :- item(X), item(Y), item(Z), X\=Y, X\=Z, Y\=Z.
perm2([X,Y,Z]) :- item(X), item(Y), X\=Y, item(Z), X\=Z, Y\=Z.

% ---------------------------------------------------------------------
% EXERCICIO 5
% ---------------------------------------------------------------------

cor(azul).
cor(verde).
cor(amarelo).
cor(vermelho).

color1([a:A, b:B, c:C, d:D, e:E]) :-
    cor(A), cor(B), cor(C), cor(D), cor(E),
    A \= B, A \= C, A \= D,
    B \= C, B \= E,
    C \= D, C \= E,
    D \= E.

% ---------------------------------------------------------------------
% EXERCICIO 7
% ---------------------------------------------------------------------

color([a:A, b:B, c:C, d:D, e:E]) :-
    cor(A),
    cor(B), A \= B,
    cor(C), A \= C, B \= C,
    cor(D), A \= D, C \= D,
    cor(E), B \= E, C \= E, D \= E.

% ---------------------------------------------------------------------
% EXEMPLO 4
% ---------------------------------------------------------------------

ação(V, acelerar) :- V < 60.
ação(V, manter)   :- V >= 60, V =< 80.
ação(V, frear)    :- V > 80.

% ---------------------------------------------------------------------
% EXEMPLO 10
% ---------------------------------------------------------------------

abs(N, A) :- if(N>=0, A is N, A is -N).

if(C, T, _) :- C, !, T.
if(_, _, E) :- E.

% ---------------------------------------------------------------------
% EXEMPLO 12
% ---------------------------------------------------------------------

for(C, A) :- C, A, fail.
for(_, _).

pes(ana).
pes(bia).

% ---------------------------------------------------------------------
% EXERCICIO 13
% ---------------------------------------------------------------------

quadrado(N) :-
    between(1, N, _),
    nl,
    between(1, N, _),
    write('* '),
    fail.

% ---------------------------------------------------------------------
% EXEMPLO 13
% ---------------------------------------------------------------------

neg(P) :- P, !, fail.
neg(_).
