Define a sum_threshold (List, Threshold, Sum) predicate to sum the elements of List that have a value greater than or equal to the Threshold.
sum_threshold([Head | Tail], Threshold, Sum) :-
Head >= Threshold,
sum_threshold(Tail, Threshold, Sum2),
Sum is Sum2 + Head.
sum_threshold([Head | Tail], Threshold, Sum) :-
Head < Threshold,
sum_threshold(Tail, Threshold, Sum).
I have compiled the file on SWI-Prolog, but when I do:
sum_threshold([5,3,10,4,7,1], 5, Sum).
It gives me
False
Why??
Head < Threshold
. – EnigmativityHead < Threshold
case – Jack23