hi, everyone, I have another problem now, a bit confused now.
Here is the code:
sumY(X1,[[X,Y]|Rest],Sum0,Sum) :-
X =:= X1,
Sum is Y+Sum0,
nl,write(Sum),write('##'),nl,
sumY(X1,Rest,Sum,Sum).
sumY(X1,[[X,Y]|Rest],Sum0,Sum) :-
X =\= X1,
Sum is Sum0,
nl,write(Sum0),write(' @ '),write(Sum),write(' *** '),nl,
sumY(X1,Rest,Sum0,Sum).
sumY(X1,[],Sum,Sum).
and I run this code as:
run :-
sumY(1,[[3,4],[1,1],[1,3],[3,3],[1,8]],0,Sum),
nl,write(Sum),nl.
the result shows as:
false.
could you give me suggestions on how to make this code work? Special thanks for giving me explainations on this.
Thank you for your answer, thank you!
Here is the code:
sumY(X1,[[X,Y]|Rest],Sum0,Sum) :-
X =:= X1,
Sum is Y+Sum0,
nl,write(Sum),write('##'),nl,
sumY(X1,Rest,Sum,Sum).
sumY(X1,[[X,Y]|Rest],Sum0,Sum) :-
X =\= X1,
Sum is Sum0,
nl,write(Sum0),write(' @ '),write(Sum),write(' *** '),nl,
sumY(X1,Rest,Sum0,Sum).
sumY(X1,[],Sum,Sum).
and I run this code as:
run :-
sumY(1,[[3,4],[1,1],[1,3],[3,3],[1,8]],0,Sum),
nl,write(Sum),nl.
the result shows as:
false.
could you give me suggestions on how to make this code work? Special thanks for giving me explainations on this.
Thank you for your answer, thank you!