Problem
You have given a 4-gallon jug and another 3gallon jugs. Neither has measuring marker on it. You have to fill the jugs with water .How can you get exactly 2 gallons of water in to 4gallons. Define set of ordered pairs integers(x,y),such that x=0,1,2,3 or 4 and y=0,1,2 or 3;X represents the number of gallons in 4galoon jug and y represents quantity of water in the 3-gallon jug.Represent the above information in a state space diagram.
Solution
You have given a 4-gallon jug and another 3gallon jugs. Neither has measuring marker on it. You have to fill the jugs with water .How can you get exactly 2 gallons of water in to 4gallons. Define set of ordered pairs integers(x,y),such that x=0,1,2,3 or 4 and y=0,1,2 or 3;X represents the number of gallons in 4galoon jug and y represents quantity of water in the 3-gallon jug.Represent the above information in a state space diagram.
Solution
The state space for this problem can be described as
The set of ordered pair of integers (x, y)
Such that
x=0, 1,2,3,4 or 4
y=0, 1, 2 or 3
x represents the quantity of water in the 4 gallon jug and
y represents the quantity of water in the 3 gallon jug.
The start state is (0, 0)
It is also known as the initial state.
The goal state is (2, n).
n-> it have any value based on the how many gallons in the 3 gallon jug.
For solving this problem we use Production rules
Production rules for Water jug problem
1- (x, y) (4,y) fill the 4- gallon jug
If x<4
2- (x,y) (x,3) fill the 3-gallon jug
If x<3
3- (x,y) (x-d,y) pour some water out of the 4- gallon jug
If x>0
4- (x,y) (x,y-d) pour some water out of the 3- gallon jug
If y>0
5-(x,y) (0,y) empty the 4- gallon jug on the ground
If x>0
6-(x,y) (x,0) empty the 3- gallon jug on the ground
If y>0d
7- (x,y) (4,y-(4-x)) pour water from the 3- gallon jug into the 4-gallon
If x+y>=4 and y>0 jug until the 4-gallon jug is full
8- (x,y) (x-(3-y),3)) pour water from the 4- gallon jug into the 3-gallon
If x+y>=3 and x>0 jug until the 3-gallon jug is full
9- (x,y) (x+y,0) pour all the water from the 3 -gallon jug into
If x+y<=4 and y>0 the 4-gallon jug
10- (x,y) (0,x+y) pour all the water from the 4 -gallon jug into
If x+y<=3 and x>0 the 3-gallon jug
11- (0,2) (2,0) pour the 2-gallon from the 3 -gallon jug into
the 4-gallon jug
12- (2,y) (0,x) empty the 2 gallon in the 4 gallon on the ground
One of the Solution to the Water jug problem
Gallons in the Gallons in the Rule Applied
4- Gallon Jug 3- gallon
0 0
0 3 2
3 0 9
3 3 2
4 2 7
0 2 5 or 12
2 0 9 or 11
State Space Diagram
![]() |
Both jug are empty |
![]() |
Fill 3 Gallon jug |
![]() |
Pour water from 3 gallon jug into 4 gallon jug |
![]() |
fill 3 gallon jug again |
![]() |
Pour water from 3 gallon jug into 4 gallon jug until it is full |
![]() |
Empty 4 gallon jug |
![]() |
pour water from 3 gallon jug into 4 gallon jug |
That's the answer Good Luck