title: Prolog Recursion removing elements at index that is multiples of n from a list where n is any number
body: <p>This is my first time asking a question here but I have a problem that I really can't wrap my head around which is Prolog recursion especially when it deals with list. So the task that I am supposed to solve is to write a drop predicate that works like this. For example, <code>drop([1,2,3,4,5,6,7,8,9], 2, L)</code> where <code>L = [1,3,5,7,9]</code> and <code>N=n</code> where elements at position n, 2n, 3n.... will be removed. The list starts from 1 is another thing to be noted. </p>
  
  <p>Here is my attempt so far and thought process: </p>
  
  <pre><code>drop([], _, []).
  
  indexOf([X|_], X, 1). %Using 1 because the question says the first element starts from 1.
  
  indexOf([_|Ys], Y , I):-
      indexOf(Ys, Y, N),
      I is N + 1.
  
  drop([X|Xs], Y, [X|_]) :-
      indexOf([X|Xs] , X , A),
      Z is A mod Y,
      Z \== 0.
  
  drop([X|Xs], Y, Zs) :-
      %indexOf([X|Xs], X, A),
      drop(Xs, Y, Zs).
  </code></pre>
  
  <p>I created an <code>indexOf</code> predicate to find the index of the elements starting from 1 . Next, my idea was to use the my first drop recursive case (in the code above it is the 5th case) to check and see whether the position of the element returns a remainder of zero when divided by the <code>Y</code> (second input). if it does not return a remainder of zero, then the <code>X</code> remains inside the list and is not dropped. Then, prolog moves on to the 2nd drop recursive case which can only be arrived when <code>Z=0</code> and it will drop <code>X</code> from the list to return <code>Z</code>s. In essence, an element with index n, 2n, 3n... that is returned by <code>indexOf</code> will be dropped if it does not return a remainder of zero when divided by <code>Y</code> (second input).</p>
  
  <p>I have not learnt Cut at this point of the course at the moment. I would appreciate if someone can point me to the right direction. I have been working on this for almost a day.</p>
  
  <p>I am still trying to adapt the logic and declarative thinking in this programming paradigm. I would appreciate it if you could share with me, how did you personally go about mastering Logic programming?</p>