I need to make a predicate that receives a numeric list and print only the numbers that end in 7 and that the sum of its digits is greater than 100
I made the predicates
This works for me:
?- filter([147, 24, 57, 17, 3667], X), write(X), nl, fail.
sumdigits(0, 0).
sumdigits(X, Z) :-
X > 0,
Z1 is X mod 10,
X2 is X // 10,
sumdigits(X2, Z2),
Z is Z1 + Z2.
filter([], []).
filter([H|X], [H|Y]) :-
sumdigits(H, D),
D > 10,
7 is H mod 10, !,
filter(X, Y).
filter([_|X], Y) :- filter(X, Y).
I get:
[147, 57, 3667]
No.
I assumed you meant that the sum of the digits was greater than 10, rather than 100.