%% Lab 4 Exercises
%% 08/10/2008

%% lab exercise 1
mySelect(X,[X|Xs],Xs).
mySelect(X,[Y|Ys],[Y|Zs]) :- X \= Y, mySelect(X,Ys,Zs).

%% lab exercise 2
addUpList(L,K) :- compute(L,K,0).
compute([],[],_).
compute([X|L],[Y|K],Z) :- Y is Z + X, compute(L,K,Y).

%% lab exercise 3
elementOccurences(_,[],0).
elementOccurences(X,[X|L],N) :- elementOccurences(X,L,M), N is M + 1.
elementOccurences(X,[Y|L],N) :- X \= Y, elementOccurences(X,L,N).

%% lab exercise 4
double([],[]).
double([X|Xs],[X,X|Ys]) :- double(Xs,Ys).

%% lab exercise 5
sum([],0).
sum([I|Is],S) :- sum(Is,S0), S is I + S0. % or plus(I,S0,S).