Water Jug Challenge

Solve the classic water jug riddle! Use two jugs with different capacities to measure an exact amount of water.

Problem Setup
Enter the capacities of both jugs and the target amount to measure
Current State
Visual representation of both jugs

Enter values and click "Solve Puzzle" to see the visualization

How It Works
Understanding the mathematical theory behind the solution

Mathematical Theory

A solution exists if and only if the target amount Z is divisible by the Greatest Common Divisor (GCD) of the two jug capacities X and Y.

Algorithm

We use Breadth-First Search (BFS) to find the shortest sequence of operations that leads to the target amount.

Allowed Operations

Fill Jug X
Fill Jug Y
Empty Jug X
Empty Jug Y
Transfer X → Y
Transfer Y → X