PROLOG Print numbers that end in 7 and the sum of its digits is greater than 100

Brian Daniel García

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 for separated but I need help making a union of the two predicates, I mean that the two predicates go into one only predicate, this is what I did so far:

%sum of digits greater than 100
 multi(X):-
0 is X mod 100
sum([],0).
sum([P|Q],Z).
multi(P), sum(Q,Z1), Z is P + Z1.
sum([P|Q],Z).
not multi(P), sum(Q,Z).

%print the numbers that end in 7
end(Y):-
7 is Y mod 10.
listend([],0).
listend([P|Q]):-
end(P),write(P), nl, listend(Q).
listend([P|Q]):-
not(end(P)), listend(Q).
Enigmativity

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PROLOG Print numbers that end in 7 and the sum of its digits is greater than 100

From Dev

Prolog - Numbers greater than x

From Dev

To print the sum of the numbers(not digits) in a string

From Dev

To print the sum of the numbers(not digits) in a string

From Dev

Why not work with numbers greater than 10 digits?

From Dev

Regex to allow decimal numbers greater than 0 and less than 100

From Dev

Directive to accept numbers greater than 0 and less than 100

From Dev

Directive to accept numbers greater than 0 and less than 100

From Dev

Find sum of prime numbers less than 100

From Dev

print matched lines when column 6 or 7 is greater than 90%

From Dev

sum if greater than in r

From Java

Given an integer N. What is the smallest integer greater than N that only has 0 or 1 as its digits?

From Dev

Generate n random numbers whose sum is m and all numbers should be greater than zero

From Dev

print if timestamp is greater than a minute

From Dev

Matching numbers greater than 40

From Dev

Given a sorted array and a parameter k, find the count of sum of two numbers greater than or equal to k

From Dev

Program in Prolog for sum of numbers in interval

From Dev

Program in Prolog for sum of numbers in interval

From Dev

Sum of numbers in multilevel list - Prolog

From Dev

Why are negative numbers greater than positive numbers?

From Dev

d3.js v4 Partition where parent's value is greater than sum of its children (node.sum)

From Dev

Print the sum of entered numbers

From Dev

Return all possible permutations and combinations of numbers from n arrays whose sum is less than m and greater than r

From Dev

Significant numbers digits of value by its error

From Dev

Generate incremented random numbers between 0 to 100 every second where new number should be greater than the previous nymber

From Dev

splitting the numbers from a text box by 4 set of numbers each getting its sum and combine all last digits of each sum from each group

From Dev

C program to print numbers between 100 and 1000 which sum of digit is 20

From Dev

Alternate to print greater than (>) symbol in Ubuntu

From Dev

Print Line if output is greater than a certain number

Related Related

  1. 1

    PROLOG Print numbers that end in 7 and the sum of its digits is greater than 100

  2. 2

    Prolog - Numbers greater than x

  3. 3

    To print the sum of the numbers(not digits) in a string

  4. 4

    To print the sum of the numbers(not digits) in a string

  5. 5

    Why not work with numbers greater than 10 digits?

  6. 6

    Regex to allow decimal numbers greater than 0 and less than 100

  7. 7

    Directive to accept numbers greater than 0 and less than 100

  8. 8

    Directive to accept numbers greater than 0 and less than 100

  9. 9

    Find sum of prime numbers less than 100

  10. 10

    print matched lines when column 6 or 7 is greater than 90%

  11. 11

    sum if greater than in r

  12. 12

    Given an integer N. What is the smallest integer greater than N that only has 0 or 1 as its digits?

  13. 13

    Generate n random numbers whose sum is m and all numbers should be greater than zero

  14. 14

    print if timestamp is greater than a minute

  15. 15

    Matching numbers greater than 40

  16. 16

    Given a sorted array and a parameter k, find the count of sum of two numbers greater than or equal to k

  17. 17

    Program in Prolog for sum of numbers in interval

  18. 18

    Program in Prolog for sum of numbers in interval

  19. 19

    Sum of numbers in multilevel list - Prolog

  20. 20

    Why are negative numbers greater than positive numbers?

  21. 21

    d3.js v4 Partition where parent's value is greater than sum of its children (node.sum)

  22. 22

    Print the sum of entered numbers

  23. 23

    Return all possible permutations and combinations of numbers from n arrays whose sum is less than m and greater than r

  24. 24

    Significant numbers digits of value by its error

  25. 25

    Generate incremented random numbers between 0 to 100 every second where new number should be greater than the previous nymber

  26. 26

    splitting the numbers from a text box by 4 set of numbers each getting its sum and combine all last digits of each sum from each group

  27. 27

    C program to print numbers between 100 and 1000 which sum of digit is 20

  28. 28

    Alternate to print greater than (>) symbol in Ubuntu

  29. 29

    Print Line if output is greater than a certain number

HotTag

Archive