1

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.

lurker
  • 56,987
  • 9
  • 69
  • 103
Eugen
  • 463
  • 1
  • 4
  • 5
  • 2
    Can you show what you've tried so far? – lurker Nov 17 '15 at 18:26
  • @lurker. Same question as: http://stackoverflow.com/q/33259691/4609915 – repeat Nov 17 '15 at 19:38
  • 1
    @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 answers – lurker Nov 17 '15 at 19:40

1 Answers1

1

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.

CapelliC
  • 59,646
  • 5
  • 47
  • 90