Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sum([],0).
- sum([N|L2],S) :- sum(L2,S2), plus(N,S2,S).
- p([],1).
- p([LL|L2],R) :- sum(LL,S), p(L2,P), mult(S,P,R).
- prodsumlist([], 1).
- prodsumlist([Head | Tail], Result) :-
- sumlist(Head, Sum_Of_Head),
- prodsumlist(Tail, ProdSum_Of_Tail),
- Result is Sum_Of_Head * ProdSum_Of_Tail.
- ?- prodsumlist([[1, 2], [3], [-4]], Result).
- Result = -36.
- prodsumlist(List, Result) :-
- xprodsumlist(List,1,Result).
- xprodsumlist([],R,R).
- xprodsumlist([Head|Rest],Sofar,Result) :-
- sumlist(Head, Sum_Of_Head),
- NewSofar is Sofar * Sum_Of_Head,
- xprodsumlist(Rest, NewSofar, Result).
Add Comment
Please, Sign In to add comment