I am trying to write a program that gives a list and back a newer list that have even numbers in the first list, as below:
evennom([1,3,2,4,3,2,1,2],out)
out = [2,4,2,2]
My Code is as below:
evennom([],[]).
evennom(H1|T1],[H2|T2):- H2 is H1 mod 2.
You are close – there needs to be something that removes the first element when the
mod 2operation fails. Also, your “copy” rule was not entirely correct.Try this: