Am trying to get prolog to compare to list of atoms for occurencs in the same location. am also trying to get it to return a list with the occurences removed, but for some reason am getting a list with the occurences, and an unbounded veriable.
My code is below.
correct(_,_,0,_):-!.
correct([H|Seq],[H|Guess],Correct,EditGuess):- N is Correct-1, del(H,EditGuess,NList), correct(Seq,Guess,N,NList),!.
correct([H1|Seq],[H2|Guess],Correct,EditGuess):- Correct(Seq,Guess,Correct,EditGuess),!.
del(X,[X|Tail],Tail):-!.
del(X,[Y|Tail],[Y|Tail1]):- del(X,Tail,Tail1).
this is my test code:
23 ?- correct([a,b,c,d],[a,c,b,d],2,G).
G = [a, d|_G540].
My code is below.
correct(_,_,0,_):-!.
correct([H|Seq],[H|Guess],Correct,EditGuess):- N is Correct-1, del(H,EditGuess,NList), correct(Seq,Guess,N,NList),!.
correct([H1|Seq],[H2|Guess],Correct,EditGuess):- Correct(Seq,Guess,Correct,EditGuess),!.
del(X,[X|Tail],Tail):-!.
del(X,[Y|Tail],[Y|Tail1]):- del(X,Tail,Tail1).
this is my test code:
23 ?- correct([a,b,c,d],[a,c,b,d],2,G).
G = [a, d|_G540].