"You are given two jugs, a 4-gallon one and a 3-gallon one. Neither has any measuring markers on it. There is a tap that can be used to fill the jugs with water. How can you get exactly 2 gallons of water into the 4-gallon jug?".
We can look at a state as a pair of numbers, where the first represents the number of gallons of water currently in Jug-A and the second represents the number of gallons in Jug-B. State space search:-
1) (x,y) ->(4,y)
if x<4
2) (x,y) ->(x,3)
if y<3
3) (x,y) ->(x-d,y)
if x>0
4) (x,y) ->(x,y-d)
if y>0
5) (x,y) ->(0,y)
if x>0
6) (x,y) ->(x,0)
if y>0
7) (x,y) ->(4,y-(4-x))
if x+y>=4,y>0
8) (x,y) ->(x-(3-y),3)
if x+y>=3,x>0
9) (x,y) ->(x+y,0)
if x+y<4,y>0
10) (x,y) ->(0,x+y)
if x+y<3,x>0
11) (0,2) ->(2,0)
12) (2,y) ->(0,y)
Solution:-
1. current state=(0,0)
2.Loop until reaching the goal state=(2,0)
(0,0)
(0,3)
(3,0)
(3,3)
(4,2)
(0,2)
(2,0)