mylen([],0).
mylen(L,Len) :- append([_],Rest,L), mylen(Rest, RLen), Len is RLen+1.

mysum([],0).
mysum(L,Sum) :- append([First],Rest,L), mysum(Rest,RSum), Sum is RSum+First.

sumpairs([],[]).
sumpairs([_],[]).
sumpairs(L,Sums) :- append([A,B],Rest,L), sumpairs(Rest,RSums), Sum is A+B, append([Sum],RSums,Sums).

contains([X],X) :- !.
contains(L,X) :- append([X],_,L), !.
contains(L,X) :- append([_],Rest,L), contains(Rest,X).

count(_,[],0).
count(Value,L,N) :- append([Value],Rest,L), count(Value,Rest,RCount), N is RCount+1, !.
count(Value,L,N) :- append([_],Rest,L), count(Value,Rest,N).

bigger(Minimum,L,Value) :- append([Value],_,L), Value > Minimum.
bigger(Minimum,L,Value) :- append([_],Rest,L), bigger(Minimum,Rest,Value).

sumpairs_gen(L,Sum) :- append([A,B],_,L), Sum is A+B.
sumpairs_gen(L,Sum) :- append([_,_],Rest,L), sumpairs_gen(Rest,Sum).
