Water Jug Problem - pritam Kumar sangram singh
Water Jug Problem - pritam Kumar sangram singh
Water Jug Problem - pritam Kumar sangram singh
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 from the start state and end up at the goal state. Production rules for the water jug
problem in AI are as follows:
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
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:
Apply a rule when the left side matches the current state
(3,0) Apply Rule 9: Pour all the water from a 3-litre jug into a 4-litre jug
(4,2) Apply Rule 7: Pour water from a 3-litre jug into a 4-litre jug until it is full
(2,0) Apply Rule 9: Pour all the water from a 3-litre jug into a 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.
(0, 1) – Rule 10: Pour all the water from the 4-litre jug into the 3-litre jug.
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: