1
votes

so i have a problem in Prolog saying that i have to remove from a list all repetitive elements. ex: L=[1,2,1,4,1,3,4] => R=[2,3]. I am not allowed to use any built in predicates. I know how to make it to remove duplicates ( like L=[1,2,1,4,1,3,4] => R=[1,2,3]), but i need only the elements that appear only once in the list.

1
Can you show what you've tried so far?lurker
@lurker. Same question as: stackoverflow.com/q/33259691/4609915repeat
@repeat yes, I originally cited that one as a duplicate, except in this case the OP has specified not allowed to use any built-in predicates, whereas that linked question seems to allow them (and all the answerslurker

1 Answers

1
votes

Let's say we have defined a service predicate count_occurrences(Elem, List, Count).

Then we can visit the list, passing the original as well, and decide element by element if we need to keep or discard it.