Water Jug Problem in Artificial Intelligence

Ayush Kumar Verma

--

😦 What is a Water Jug Problem?

You are given two jugs, a 4-gallon jug, and a 3-gallon jug. Neither has any measuring marks on it. There is a pump that can be used to fill the jugs with water. How can you fill exactly 2 gallons of water into the 4-gallon jug?

Photo by Michał Parzuchowski on Unsplash

To solve this problem we will make some assumptions:

  • There is an infinite amount of water supply.
  • We can fill/empty jugs completely.

Here, let’s consider the initial state (both jugs empty) as (0, 0), and the final goal state will be (2, n) where n can have any value and the 4-gallon jug has 2-gallons of water in it.

Let the state space for this problem be denoted by a set of ordered pairs of integers (C1, C2), where C1 and C2 represent the quantity of water, and C1 = {0, 1, 2, 3, 4} and C2 = {0, 1, 2, 3}.

Defining a set of rules that will help us solve this problem.

Image by Ayush Kumar Verma

There can be different approaches to solve this problem, one of the approaches is as follows:

Image by Ayush Kumar Verma

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Ayush Kumar Verma
Ayush Kumar Verma

Written by Ayush Kumar Verma

My two major interests and passions are Computers and Designing, and I believe that there is a creative fusion between these disciplines.

No responses yet

Write a response