I've been searching for something that might help me with my problem all over the internet but I haven't been able to make any progress. I'm new to logic programming and English is not my first language so apologize for any mistake.
Basically I want to implement this prolog program: discord/3 which has arguments L1, L2 lists and P where P are the indexes of the lists where L1[P] != L2[P] (in Java). In case of different lengths, the not paired indexes just fail. Mode is (+,+,-) nondet.
I got down the basic case but I can't seem to wrap my head around on how to define P in the recursive call.
discord(_X,[],_Y) :-
fail.
discord([H1|T1],[H1|T2],Y) :-
???
discord(T1,T2,Z).
discord([_|T1],[_|T2],Y) :-
???
discord(T1,T2,Z).
The two clauses above are what I came up to but I have no idea on how to represent Y - and Z - so that the function actually remembers the length of the original list. I've been thinking about using nth/3 with eventually an assert but I'm not sure where to place them in the program.
I'm sure there has to be an easier solution although. Thanks in advance!
?- discord([a,b,c],[x,b,y], [1,3]).should be true? - user1812457(+,+,-)so a sample query could be something like?- discord([a,b,c], [d,e,c], X)which should give answersX=1; X=2or?- discord([1,2,3], [1,2,3], X)which should answerfalse- GoldenMatdif(X, Y), nth1(P, L1, X), nth1(P, L2, Y)- user1812457P=1- because the recursion doesn't remember the length of the original list!discord(_X,[],_Y) :- fail.discord([],_X,_Y) :- fail.discord([X|T1],[Y|T2],P) :- dif(X,Y), nth1(P, [X|T1], X), nth1(P, [Y|T2], Y), discord(T1,T2,P).- GoldenMatdiscord/3. You can also write a recursive predicate for this, but maybe unnecessary. - user1812457