Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate the sum of a list of lists

Status
Not open for further replies.

lauraberishaj

Programmer
Feb 16, 2007
4
SE
I'm new in Prolog,
Can anybody help me how to calculate the sum of a list of lists?

Thank You,
Laura
 
sum([], 0) :- !.

sum(N, N) :- number(N), !.

sum([H|T], N) :-
sum(H, N1),
sum(T, N2),
N is N1 + N2.

--Did it ..yeeeaaahhhh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top