Skip to content

sheikhartin/water-jug-puzzle-from-scratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Water Jug Puzzle From Scratch

GitHub repo status GitHub license GitHub contributors GitHub tag (latest by date) GitHub repo size

Water jug is a classic and also interesting puzzle to solve. You are given some number of jugs with a capacity and a initial state of water in each jug. Now you should do some operations to make the water in one jug to be equal to the goal amount.

This puzzle in computer science is usually solved in two ways; the simplest way is to act step by step and the other is to use trees to show all possible situations ahead. Here I will try to implement the simplest way.

You can not drink under a hockey mask

Rules

There is no any formal strategy and you have to make one for yourself... Just kidding, you can use some standard answers for specific situations!

Let's solve a few examples to understand it better, but before that we have to respect some limitations. The operations you can perform are:

  • Empty a jug
  • Fill a jug
  • Pour water from one jug to another until one of the jugs is ethier full or empty

Examples

Read the states like this: (amount of jug A/capacity of jug A, amount of jug B/capacity of jug B) [-> goal amount]

Situation no. 1

Situation no. 2

Situation no. 3

Situation no. 4

Situation no. 5

Screenshots

Solved puzzle with default values Another solved puzzle with huge jugs Manually solved puzzle And a unsolved puzzle

Usage

Install the dependencies:

pip install -r requirements.txt

Run the core logic directly from the command line:

python core.py

Or even better, use the graphical interface:

python app.py

License

This project is licensed under the MIT license found in the LICENSE file in the root directory of this repository.

About

Nothing, we just have to move the water between a few jugs to reach the desired amount...

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages