I have this program in Prolog, it removes elements at each nth element from a list, like: removenth([1,2,3,4,5,6], 2, R). it should return : R = [1,3,5].
I have this:
removeallNth(F, N, R):- removeallNth(F, N, 1, R).
removeallNth([], _, _, R).
removeallNth([H|T], N, C, R):- N \== C, Nc is C + 1, concat(R,H,S),
removeallNth(T, N, Nc, S).
removeallNth([_|T], N, C, R):- N == C, removeallNth(T, N, 1, R).
The problem is that it returns true instead of R = [1,3,5]. I checked in SWI-Prolog debugger and it arrives to the correct result but then it keeps checking stuff. I understand it has to do with unification but I don't know how to apply it.