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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

another 'false' problem

Status
Not open for further replies.

jonison

Programmer
Jul 12, 2009
4
GB
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!
 
What do you expect ?
Can you explain what the code should do ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top