0% found this document useful (0 votes)
6 views5 pages

Water Jug Problem - pritam Kumar sangram singh

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

Name : pritam Kumar sangram singh

Course : MBA Marketing Management


Div : A
Roll No : MITU22MBAM0032

Question 1
The water Jug Problem, as the name suggests, is a problem where two jugs of water
are given, say one is a 4-litre one, and the other one is a 3-litre one, but none of the
measuring markers is mentioned on any of it. There is a pump available to fill the jugs
with water. How can you exactly pour 2 liters of water into a 4-litre jug? Assuming that
both the jugs are empty, the task is to find a solution to pour 2-litre water into a 4-litre
jug.

Answer :
In production rules for the water jug problem, let x denote a 4-litre jug, and y denote a 3-
litre jug, i.e. x=0,1,2,3,4 or y=0,1,2,3

Start state (0,0)

Goal state (2,n) from any n

Start from the start state and end up at the goal state. Production rules for the water jug
problem in AI are as follows:

1. (x,y) is X<4 -> (4, Y) Fill the 4-litre jug

2. (x, y) if Y<3 -> (x, 3) Fill the 3-litre jug

3. (x, y) if x>0 -> (x-d, d) Pour some water from a 4-litre jug
4. (x, y) if Y>0 -> (d, y-d) Pour some water from a 3-litre jug

5. (x, y) if x>0 -> (0, y) Empty 4-litre jug on the ground

6. (x, y) if y>0 -> (x,0) Empty 3-litre jug on the ground

(x, y) if X+Y >= 4 and y>0 -> (4,


7. Pour water from a 3-litre jug into a 4-litre jug until it is full
y-(4-x

(x, y) if X+Y>=3 and x>0 -> (x-


8. Pour water from a 3-litre jug into a 4-litre jug until it is full
(3-y), 3))

(x, y) if X+Y <=4 and y>0 ->


9. Pour all the water from a 3-litre jug into a 4-litre jug
(x+y, 0

(x, y) if X+Y<=3 and x>0 -> (0,


10. Pour all the water from a 4-litre jug into a 3-litre jug
x+

11. (0, 2) -> (2, 0) Pour 2-litre water from 3-litre jug into 4-litre jug

12. (2, Y) -> (0, y) Empty 2-litre in the 4-litre jug on the ground.
Here is the water jug problem solution in AI is as follows:

Current state (0,0)

Loop till the goal state (2,0) is reached.

 Apply a rule when the left side matches the current state

 Set the new current state to the resulting state

Start state (0,0)

(0,3) Apply Rule 2, Fill the 3-litre Jug

(3,0) Apply Rule 9: Pour all the water from a 3-litre jug into a 4-litre jug

(3,3) Apply Rule 2, Fill the 3-litre Jug

(4,2) Apply Rule 7: Pour water from a 3-litre jug into a 4-litre jug until it is full

(0,2) Apply Rule 5, Empty 4-litre jug on the ground

(2,0) Apply Rule 9: Pour all the water from a 3-litre jug into a 4-litre jug

Another water jug problem solution is:

(0, 0) – Start State

(4, 0) – Rule 1: Fill the 4-litre jug

(1, 3) – Rule 8: Pour water from the 4-litre jug into the 3-litre jug until the 3-litre jug is
full.

(1, 0) – Rule 6: Empty the 3-litre jug on the ground

(0, 1) – Rule 10: Pour all the water from the 4-litre jug into the 3-litre jug.

(4, 1) – Rule 1: Fill the 4-litre jug


.(2, 3) – Rule 8: Pour water from the 4-litre jug into the 3-litre jug until the 3-litre jug is
full.

Goal State reached.

Question 2

You have an 8 litre jug full of water and two smaller jugs, one that contains
5 litres and the other 3 litres. None of the jugs have markings on them, nor
do you have any additional measuring device.You have to divide the 8 litres
of water equally between your two best friends, so that each gets 4 litres of
water. How can you do this?

Answer :

 First, water is poured from the 8 litre jug into the 5 litre jug, leaving 3
litres of water in the original 8 litre jug.
 Next, water is poured from the 5 litre jug into the 3 litre jug, so we
now have 3 litres of water in the 8 litre jug, 2 litres of water in the 5
litre jug and 3 litres of water in the 3 litre jug.
 The 3 litre jug is emptied into the 8 litre jug, so the 8 litre jug now
contains 6 litres of water.
 The 2 litres of water in the 5 litre jug are now poured into the empty 3
litre jug.
 Water is poured from the 8 litre jug (which at this stage contains 6
litres) into the empty 5 litre jug. We now have 5 litres of water in the 5
litre jug, 2 litres of water in the 3 litre jug and 1 litre of water in the 8
litre jug.
 Water is poured from the 5 litre jug to fill the 3 litre jug which already
contains at this stage 2 litres of water.
 We are left with 4 litres of water in the 5 litre jug which is given to one
friend, and 3 litres of water in the 3 litre jug that is poured back into
the 8 litre jug that already contains 1 litre of water. This gives 4 litres
of water which are given to the second friend.
The whole scenario can be summarised using numbers in brackets to
denote the litres of water at each stage in each of the 8 litre, 5 litre and 3
litre jugs, respectively:

[[8,0,0] rightarrow [3,5,0] rightarrow [3,2,3] rightarrow [6,2,0] rightarrow


[6,0,2] rightarrow [1,5,2] rightarrow [1,4,3] rightarrow [4,4,0]]

You might also like