Game technique · Water Jug
Water Jug Puzzles: GCD and BFS
With two jug capacities A and B, a target no greater than the larger jug is measurable exactly when it is divisible by gcd(A, B).
🎮 Play Water Jug →How it works
With two jug capacities A and B, a target no greater than the larger jug is measurable exactly when it is divisible by gcd(A, B).
Example
For 5-liter and 3-liter jugs, 4 liters is possible. Breadth-first search finds a shortest sequence of fills, empties, and pours.
Key point
With two jug capacities A and B, a target no greater than the larger jug is measurable exactly when it is divisible by gcd(A, B).