Friday, July 6, 2007

water jug problem

domains
j1=integer
j2=integer
predicates
water(j1,j2)
water(integer,integer,integer,integer)
clauses
water(2,B,_,_):-B<4.
water(A,_):-A>4,write("Jug One capacity exceeded").
water(_,B):-B>3,write("Jug two capacity exceeded").
water(A,B):-A=4,B=0,X=1,Y=3,write("jug1=",X," ","jug2=",Y).
water(P,Q):-P=1,Q=3,P1=1,Q1=0,write("jug1=",P1," ","jug2=",Q1).
water(P,Q):-P=1,Q=0,P1=0,Q1=1,write("jug1=",P1," ","jug2=",Q1).
water(P,Q):-P=0,Q=1,P1=4,Q1=1,write("jug1=",P1," ","jug2=",Q1).
water(P,Q):-P=4,Q=1,P1=2,Q1=3,write("jug1=",P1," ","jug2=",Q1),write("Solution reached").

6 comments:

Aggrey Mullwani said...

nice work
just asking, what is the predicate to be checked?

Abhishek said...
This comment has been removed by the author.
Ankesh Kumar said...

@jimmy: abe chutiya nahi banaya.
go to the goal window and run the program using:
Goal: water(4,0)

The output for this query is the next input as water(-,-)

Abhishek said...
This comment has been removed by the author.
Unknown said...

Error illegal number of parameter

Unknown said...

Which prolog did you use?
swi or turbo or gnu.???