I'm learning Prolog via learnprolognow. Currently I'm on chapter4 and am stuck on the second exercise.
"Now write a 3-place predicate combine2 which takes three lists as arguments and combines the elements of the first two lists into the third as follows:
?- combine2([a,b,c],[1,2,3],X).
X = [[a,1],[b,2],[c,3]] "
My implementation of this is:
combine2([],[],[]).
combine2([H1|T1],[H2|T2],[[H1,H2],R]):-
combine2(T1,T2,R).
The result of the query above tho is:
X = [[a, 1], [[b, 2], [[c, 3], []]]] ;
I do not know how to re-write it, so in the last step the program is not adding an empty list. I am open to suggestions/hints/solutions.
Thank you and have a nice sunday!