title: Prolog Finding Kth element in a list
body: <p>I am trying write a predicate in prolog to find Kth element in a list.
  Example:</p>
  
  <pre><code>?- element_at(X,[a,b,c,d,e],3).
  X = c
  </code></pre>
  
  <p>my code as follows</p>
  
  <pre><code>k_ele(X,[X|_],1).
  k_ele(X,[_|T],Y) :- Y &gt; 1,Y is Y - 1, k_ele(X,T,Y).
  </code></pre>
  
  <p>But no use, I found solution on Internet as </p>
  
  <pre><code>element_at(X,[X|_],1).
  element_at(X,[_|L],K) :- K &gt; 1, K1 is K - 1, element_at(X,L,K1).
  </code></pre>
  
  <p>Which is same as my logic except they used one extra variable K1.</p>
  
  <p>What is wrong with my code, why I need another variable ? </p>