LogicholicLogicholic
← All techniques

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.

5L3L43
Water Jug Puzzles: GCD and BFS

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).

🎮 Play Water Jug →