title: Searching a list for (same) two elements in Prolog
body: <p>How can I search a list in Prolog for a specific element that appears more than once?</p>
  
  <p>For example, if we are searching the list <code>[1,2,3,4,1]</code> for the element <code>1</code>, Prolog should return <code>true</code>, but otherwise <code>false</code> for all other numbers.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>duplicate([], _) :-
     false,
     !.
  duplicate([X|_], X) :-
     true,
     !.
  duplicate([H|T], X) :-
     T = [_|T1],
     duplicate(T, X),
     duplicate(T1, X).
  </code></pre>
  
  <p>My basic idea is to search the list until I find the element I am looking for, then search the tail of the list for the item again. I do not want to use the member() function provided by Prolog.</p>
  
  <p>Prolog should also return the elements that appear more than once if asked by the query: <code>duplicate([1,2,3,4,1], X)</code>, should print <code>X = 1</code>.</p>