This is my first time here and I know there are already posts about this but don't seem to be the same way I am suppose to code it. I just keep getting the answer false.
I enter : solve(0,0).
Result is false.
Code.
solve(5,_).
solve(X,Y):- X < 7,
\+ member((7,Y),L),
concat(E,[(X,Y)],L),
write('Fill 7 litre jug from tap.\n'),
solve(7,Y).
solve(X,Y):- Y < 4,
\+ member((X,4),L),
concat(E,[(X,Y)],L),
write('Fill 4 litre jug from tap.\n'),
solve(X,4).
solve(X,Y):- X+Y >= 7,
Y > 0,
Z is Y - (7 - X),
\+ member((7,Z),L),
concat(E,[(X,Z)],L),
write('Fill 7 litre jug with 4 litre jug.\n'),
solve(7,Z).
solve(X,Y):- X+Y >= 4,
X > 0,
Z is X - (4 - Y),
\+ member((Z,4),L),
concat(E,[(Z,Y)],L),
write('Fill 4 litre jug with 7 litre jug.\n'),
solve(Z,4).
solve(X,Y):- X+Y < 4,
Y > 0,
Z is X + Y,
\+ member((Z,0),L),
concat(E,[(Z,Y)],L),
write('Empty 4 litre jug into 7 litre jug.\n'),
solve(Z,0).
solve(X,Y):- X+Y < 7,
X > 0,
Z is X+Y,
\+ member((0,Z),L),
concat(E,[(X,Z)],L),
write('Empty 7 litre jug into 4 litre jug.\n'),
solve(0,Z).
solve(X,Y):- X > 0,
\+ member((0,Y),L),
concat(E,[(X,Y)],L),
write('Empty 7 litre jug.\n'),
solve(0,Y).
solve(X,Y):- Y > 0,
\+ member((X,0),L),
concat(E,[(X,Y)],L),
write('Empty 4 litre jug.\n'),
solve(X,0).
member(X,[X|L]).
member(X,[L|L]):-
member(X,L).
concat([],L,L).
concat([X|A],B,[X|L]):-
concat(A,B,L).
Any help is much appreciated. Thanks.
member(X,[L|L]):- member(X,L).should probably bemember(X,[Y|L]):-X \= Y, member(X,L).but SWI prolog has a built in predicate for this, so it's not needed. Also, each time you have this:solve(X,Y):- X < 7, \+ member((7,Y),L),..., the listLhasn't been instantiated, so\+ member((7,Y),L)will always fail. - lurker(7,Y)is in the list and if it is not to add it to it. - JohnMcDonagh22membersucceed, which means\+ memberwill fail. - lurker