I'm trying to add either 1 or 2 to numbers in a list in SWI-Prolog.
I've managed to add 1 or 2 to the head of the list however I'm having difficulties adding onto each element on the tail of the list. I don't want to add 1 or 2 to EVERY element at the same time just at separate times. I.e. If my input is add([2,3,4], X).
I would like the possibilities of X to be the following:
X = [3,3,4]
X = [4,3,4]
X = [2,4,4]
X = [2,5,4]
X = [2,3,5]
X = [2,3,6]
My code at present is:
add([],[]).
add([H1|T1],[H2|T2]) :-
is(H2,+(H1,1)), T1=T2;
is(H2,+(H1,2)), T1=T2.
Obviously this only adds 1 or 2 onto the head of the list and not the tail. Therefore does anyone know how I may go about adding 1 or 2 onto the elements in the tail of my list?