%% Some possible solutions for Prolog programming parts of DM22 exam
%% summer 2007


%%%%%% Opgave 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

pairsums([],[]).
pairsums([_],[]).
pairsums([X,Y|Rest],[S|L]) :- S is X+Y, pairsums([Y|Rest],L).

zip([],L,[]).
zip([X|L1],[],[]).
zip([X|L1],[Y|L2],[(X,Y)|L3]) :- zip(L1,L2,L3).

zipWith(F,[],L,[]).
zipWith(F,[X|L1],[],[]).
zipWith(F,[X|L1],[Y|L2],[Z|L3]) :- Func=..[F,X,Y,Z], call(Func), zipWith(F,L1,L2,L3).

%% Does NOT work:
%% zipWith(F,[X|L1],[Y|L2],[Z|L3]) :- F(X,Y,Z), zipWith(L1,L2,L3).


add(X,Y,Z) :- Z is X+Y.



%%%%%% Opgave 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


a(X,Y) :- c(X),c(Y).
b(X,Y) :- !,c(X),!,c(Y),!.
c(1).
c(2) :- !.
c(3).
