Guest_imported
New member
- Jan 1, 1970
- 0
How do i write a program that computes the sum of nested lists of numbers?
The list can contain either just numbers, of lists of numbers.
An example of how the program should work is:
?-sum([1,2,[3,4],5],S) would return S=15.
Right now I can add just numbers, but not lists of numbers:
sum([],0).
sum([H|T],N) :-
sum(T,N1),
N is H + N1.
The list can contain either just numbers, of lists of numbers.
An example of how the program should work is:
?-sum([1,2,[3,4],5],S) would return S=15.
Right now I can add just numbers, but not lists of numbers:
sum([],0).
sum([H|T],N) :-
sum(T,N1),
N is H + N1.