问题
I'm new in prolog language i do my researching to find how to do sum in prolog and i did it, but i didn't find any source how to remove duplicate from a list and do sum.
the sum code i have is this
sum([], 0).
sum([H|T], N):- sum(T, X),
N is X + H.
but i need to do sum unique number in a list, but i don't know how to do it.
Such as i have a list
?- Sum([1,2,3,3],U) // removing duplicate of 3.
U = 6
can you help me understanding how to do unique number with sum? is my rule good? or do the unique in query ?
来源:https://stackoverflow.com/questions/59009100/sum-unique-number-in-a-list-in-prolog