Home > Net >  How can I return a list of numbers from a given list that mod 0 a target number?
How can I return a list of numbers from a given list that mod 0 a target number?

Time:03-28

In my function modded(X,Y,Z), a list is generated based off of a given number Y and a given list of numbers Z. What I am trying to do is go through the list Z for each of its values and see if the current value in the list will cleanly divide Y, (Y/Zz == 0). I am a bit confused on how to access each of Z's values since Prolog does not have traditional iterators.

Expected behavior would be for modded(X,16,[2,3,4,5,7,8]) to return a list of [2,4,8]. Only complete divisors are allowed.

modded([],Y,Z):-
    % X is the generated list, Y is the number, Z is a list of given numbers.
               
  • Related