%DCC-FCUP - Logica e Programacao 2011-2012

primcol([],[]).
primcol([[H|T]|R],[H|Hs]):- primcol(R,Hs).

seguintes([],[]).
seguintes([[H|T]|R],[T|Ts]):-seguintes(R,Ts).

transp([[]|_],[]).
transp(R,[H|T]):- primcol(R,H), seguintes(R,C),transp(C,T).

partecol([],[],[]).
partecol([[H|T]|R],[H|Hs],[T|Ts]):- partecol(R,Hs,Ts).

transp1([[]|_],[]).
transp1(R,[H|T]):- partecol(R,H,C), transp1(C,T).

%% occ_rep([],C,N,[N*C1]):- C1 is C-N+1.
%% occ_rep([X|R],X,N,L):- N1 is N+1, occ_rep(R,X,N1,L).
%% occ_rep([X|R],C,N,[N*C1|L]):- X\=C, C1 is C-N+1, occ_rep(R,X,1,L).

occ_rep([],C,N,[N*C]).
occ_rep([X|R],X,N,L):- N1 is N+1, occ_rep(R,X,N1,L).
occ_rep([X|R],C,N,[N*C|L]):- X\==C, occ_rep(R,X,1,L).


sum_cum(A,B):- saux(A,0,B).

saux([],_,[]).
saux([X|R],C,[Y|Rs]):- Y is C+X, saux(R,Y,Rs).

split_int([],[],[]).
split_int([X|L],R,[X|T]):- 0 is X mod 2, split_int(L,R,T).
split_int([X|L],[X|T],R):- 1 is X mod 2, split_int(L,R,T).

% utilizacao do !
max1(X,Y,X):- X >= Y.
max1(X,Y,Y):- X< Y.

max(X,Y,X):- X >= Y, !.
max(X,Y,Y):- X< Y.

max2(X,Y,X):- X >= Y, !.
max2(X,Y,Y).
