I just started in Prolog and have the problem:
(a) Given a list L, an object X, and a positive integer K, it returns the position of the K-th occurrence of X in L if X appears at least K times in L otherwise 0.
The goal
pos([a,b,c,b],b,2,Z)
should succeed with the answerZ = 4
.
So far I have:
pos1([],H,K,F).
pos1([H],H,1,F).
pos1([H|T],H,K,F):- NewK is K - 1, pos1(T,H,NewK,F), F is F + 1.
pos1([H|T],X,K,F):- pos1(T,X,K,F).
But I can't figure out why I'm getting:
ERROR: is/2: Arguments are not sufficiently instantiated
Any help would be much appreciated!