Question: Write the following Prolog rule: Implement a function removeNth that, given a list L and an integer N, will eliminate every Nth element from list
Write the following Prolog rule:
Implement a function removeNth that, given a list L and an integer N, will eliminate every Nth element from list L and return the result. For example:
?-removeNth([a,b,c,d,e,f,g,h,i,j],2,X). would result in Prologs response
X=[a,c,e,g,i]
Hint: create a clause
removeNth(L,N,M) :- copySome(L,N,M,N) %you can, of course use another name than copySome
copySome(L,N,M,K) [notice the K] will copy k-1 elements, ignoring the next element and, after this remove every Nth elements
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
