title: Counting duplicate elements in prolog
body: <p>i'm having problems with this subject in Prolog.
  The thing is that I want to count the number of repeated elements appearing in a list,
  and I also want to fill, in another list with 1, for each appearance of duplicated elements and a 0 if is not duplicated, e.g.</p>
  
  <p>I have a list like this: [420,325,420,582,135,430,582], and the result should be [1,0,1,1,0,0,1].</p>
  
  <p>I've tried some code snippets and it's driving me nuts.</p>
  
  <p>The last code i've tried is: </p>
  
  <pre><code>count_duplicates([],[]).
  count_duplicates([Head|Tail],[1|LS]):-
      member(Head,Tail),
      count_duplicates([Tail|Head],LS).
  
  count_duplicates([Head|Tail],[0|LS]):-
      \+ member(Head,Tail),
      count_duplicates([Tail|Head],LS).
  </code></pre>
  
  <p>this predicate receive a list and have to generate the result list</p>
  
  <p>Thanks in advance</p>