title: Even and Odd lists
body: <p>I am trying to implement a Prolog program that will split a list in two lists. The first one will contain the numbers in even positions and the second one the numbers is odd positions.</p>
  
  <p>E.g.: <code>even_odd([1,2,4,7,5],Even,Odd).</code> will result in <code>Even=[2,7].</code> and <code>Odd=[1,4,5].</code></p>
  
  <p>I have found more elegant solutions than mine googling the problem, however I would like to find where the problem lies with in my code (probably operator misuse) because I really think I have a very bad understanding of Prolog operators (especially in arithmetic comparison). Also googling it only makes it worse, every website has a completely different explanation.</p>
  
  <p>My code:</p>
  
  <pre><code>even_odd([], [], []).
  even_odd([H|T], Even, Odd) :-
      length([H|T], X),
      X mod 2 is 0,
      append(Even1, H, Even),
      even_odd(T, Even1, Odd).
  even_odd([H|T], Even, Odd) :-
      length([H|T], X),
      X mod 2 is 1,
      append(Odd1, H, Odd),
      even_odd(T,Even,Odd1).
  </code></pre>
  
  <p>I have tried tracing and I know the problem lies in the <code>X mod 2 is 1</code> or <code>0</code>, none of them is ever true. If I have a list of three elements and change condition to <code>X is 3</code> it is completely fine, but the division seems to mess it up, so any ideas?</p>