database
rstate(integer,integer)
predicates
state(integer,integer)
clauses
state(2,_).
state(0,0):-
not(rstate(0,0)),
assert(rstate(0,0)),
state(0,0).
state(X,Y):-
X < 4,
not(rstate(4,Y)),
assert(rstate(4,Y)),
write("\n Rule 1 => (4,",Y,")"),
state(4,Y).
state(X,Y):-
Y < 3,
not(rstate(X,3)),
assert(rstate(X,3)),
write("\n Rule 2 => (",X,",3)"),
state(X,3).
state(X,Y):-
X>0,
not(rstate(0,Y)),
assert(rstate(0,Y)),
write("\n Rule 5 => (0,",Y,")"),
state(0,Y).
state(X,Y):-
Y>0,
not(rstate(X,0)),
assert(rstate(X,0)),
write("\n Rule 6 => (",X,",0)"),
state(X,0).
state(X,Y):-
X+Y >= 4,
Y > 0,
Z=Y-(4-X),
not(rstate(4,Z)),
assert(rstate(4,Z)),
write("\n Rule 7 => (4,",Z,")"),
state(4,Z).
state(X,Y):-
X+Y >= 3,
X>0,
Z=X-(3-Y),
not(rstate(Z,3)),
assert(rstate(Z,3)),
write("\n Rule 8 => (",Z,",3)"),
state(Z,3).
state(X,Y):-
X+Y <= 4,
Y > 0,
Z=X+Y,
not(rstate(Z,0)),
assert(rstate(Z,0)),
write("\n Rule 9 => (",Z,",0)"),
state(Z,0).
state(X,Y):-
X+Y <= 3,
X>0,
Z=X+Y,
not(rstate(0,Z)),
assert(rstate(0,Z)),
write("\n Rule 10 => (0,",Z,")"),
state(0,Z).
state(X,Y):-
X=0,
Y=2,
not(rstate(2,0)),
assert(rstate(2,0)),
write("\n Rule 11 => (2,0)"),
state(2,0).
state(X,Y):-
X=2,
assert(rstate(0,Y)),
write("\n Rule 12 => (0,",Y,")"),
state(0,Y).
goal
makewindow(1,2,3,"Water Jug Problem",0,0,25,80),
write("Initially state(0,0)"),
state(0,0),
save("output.txt").
OUTPUT
Initially state(0,0)
Rule 1 => (4,0)
Rule 2 => (4,3)
Rule 5 => (0,3)
Rule 9 => (3,0)
Rule 2 => (3,3)
Rule 7 => (4,2)
Rule 5 => (0,2)
Rule 9 => (2,0)
Press the SPACE bar
output.txt
rstate(0,0)
rstate(4,0)
rstate(4,3)
rstate(0,3)
rstate(3,0)
rstate(3,3)
rstate(4,2)
rstate(0,2)
rstate(2,0)