## Water Jug Problem in AI

Problem: We have 2 Jugs, One is 4L, and Second one 3L The problem is we have to fill the 4L Jug with 2L Water but the twist is we have not any marked on the Surface of any Jug. So, How we can fill the Jug?

Assumption: We have an unlimited source of water. Remember that we have no mark of measurement on Jug, and we don’t have any measurement instrument.

Representation:

We represent jug by (x,y) x represents 4L Jug y represents 3L Jug.

## Water Jug Problem in AI

### Problem:

A Water jug problem in ai: It is a staring phase of AI.

We have 2 Jugs, One is 4L, and the Second one 3L The problem is we have to fill the 4L Jug with 2L Water but the twist is we have not any marked on the Surface of any Jug. So, How we can fill the Jug?

### Assumption:

We have an unlimited source of water. Remember that we have no mark of measurement on Jug, and we don’t have any measurement instrument.

### Representation:

We represent jug by (x,y) x represents 4L Jug y represents 3L Jug.

More explanation of the water jug problem in ai

No. |
Initial State |
Condition |
Final State |
Description |

1 | (x,y) | If x<4 | (4,y) | Fill 4L jug |

2 | (x,y) | if y<3 | (x,3) | Fill 3L jug |

3 | (x,y) | If x>0 | (0,y) | Empty 4L jug |

4 | (x,y) | If y>0 | (x,0) | Empty 3L jug |

5 | (x,y) | x+y<=3 | (0,x+y) | Transfer 4L to 3L jug |

x+y>3 | (x-(3-y),3) | |||

6 | (x,y) | x+y<=4 | (x+y,0) | Transfer 3L to 4L jug |

x+y>4 | (4,y-(4-x)) |

Here, We find the condition in all the states. It is helping our code done in python.

Here, We can do the program in python in that user have to enter maximum capacity of both jug

We try to solve water jug problem using Python Language.

a = 0

b = 0

maxcap1 = int(input(“Enter Maximum capacity of Jug 1: “))

maxcap2 = int(input(“Enter Maximum capacity of Jug 2: “))

x = int(input(“Enter Goal value of Jug 1: “))

y = int(input(“Enter Goal value of Jug 2: “))

def menuinput():

print(“1.For Fill Jug 1”)

print(“2.For Fill Jug 2”)

print(“3.For Empty Jug 1”)

print(“4.For Empty Jug 2”)

print(“5.For Transfer form Jug 1 to Jug 2”)

print(“6.For Transfer form Jug 2 to Jug 1”)

global k

k = int(input(“Enter your Choice: “))

while True:

if a == x and b == y:

break

menuinput()

if k == 1:

if a < maxcap1:

a = maxcap1

print(a,”,”,b)

elif k == 2:

if b < maxcap2:

b = maxcap2

print(a,”,”,b)

elif k == 3:

a = 0

print(a,”,”,b)

elif k == 4:

b = 0

print(a,”,”,b)

elif k == 5:

if a+b > maxcap2:

a = a – (maxcap2 – b)

b = maxcap2

print(a,”,”,b)

else:

b = a + b

a = 0

print(a,”,”,b)

elif k == 6:

if a+b <= maxcap1:

a = a + b

b = 0

print(a,”,”,b)

else:

a = maxcap1

b = b – (maxcap1 – a)

print(a,”,”,b)

print(“Goal is achieved”)

#### Other Posts on AI

https://easyengineering.in/category/ai/

#### Other Computer-related Posts

https://easyengineering.in/category/computer/

#### What is AI

https://easyengineering.in/what-is-artificial-intelligence/

#### Explanation of AI

https://www.zdnet.com/article/what-is-ai-everything-you-need-to-know-about-artificial-intelligence/

## Be the first to comment