sumList predicate needs to check to see if their Sum is equal to the sum of all the elements in the list

Posted by nick bonnet on Stack Overflow See other posts from Stack Overflow or by nick bonnet
Published on 2012-12-10T22:36:56Z Indexed on 2012/12/10 23:04 UTC
Read the original article Hit count: 145

Filed under:
|

I am implementing a method that when given Sum and a List. It will check to see that if you add the elements in the list, their sum is equal to the Sum given. Here is what I am trying to do thus far, but I am pretty sure it is wrong... I'm not really sure how to think about it.

  sumList([],0).
  sumList([X|Xrest], Sum) :-
     sumList[Xrest, Sum1),
     Sum is X + Sum1.

Could you give me a point in the right direction or at least let me know how to try to think about the problem?

© Stack Overflow or respective owner

Related posts about prolog

Related posts about swi-prolog