I got an assignment where I need to write a predicate "same_position(L1,L2,E1,E2)" where L1 and L2 are lists, E1 is a element from L1 and E2 is a element from L2. the predicate is true when E1 and E2 are in the same positions in their lists. I need to solve this problem using recursion
this is my solution to the problem:
same_position([L1|_],[L2|_],E1,E2) :- L1==E1,L2==E2.
same_position([_|L1],[_|L2],E1,E2) :- same_position(L1,L2,E1,E2).
this works, but not fully as expected, along with the assignment came a sample output where the below part is the problem. The expected output gives values for L before printing false where mine solution simply prints false. what am I doing wrong?
Expected output:
?- same_position(L, [a,a,c], 3, a).
L = [3|_G1667] ;
L = [_G1769, 3|_G1772] ;
false.
Mine output:
?- same_position(L,[a,a,c],3,a).
false.