This puzzle dates back at least as far as the 1920s, and quite possibly earlier still.
One solution is as follows:
- Fill the 5-liter container.
- Fill the 3-liter container from the 5-liter container, leaving 2 liters.
- Empty the 3-liter container. Then, pour the remaining 2 liters from the 5- to the 3-liter container.
- Refill the 5-liter, then fill the 3-liter from the 5-liter container. Leaving 4 liters in the 5-liter container.
Another alternate solution, though this one requires several assumptions: The containers must have at least one line of symmetry when looking at them from the top, and they must have a constant width. (Cylinders or rectangular prisms meet this requirement.)
- Fill the 5-liter container, then place one part of the bottom down, and tilt it until the water level makes a straight line from the upper edge of the bottom to the bottom edge of the lip.
- Do the same thing with the 3-liter container, and pour it into the 5-liter container.
- 2.5 + 1.5 = 4
It bears noting that this puzzle, like many other stock puzzles, is usually difficult only because the solver is overthinking it. In practice, if you actually have the two jugs, and you just start filling one jug and pouring it into the other, the solution presents itself very quickly. (This is incorporated in some tellings of the riddle, which demand that you come up with the answer in less than a minute, as An Aesop about the value of trying things out rather than just sitting there thinking.)
Maths nerd bit: You're looking for the smallest x and y that satisfy 3x−5y=4; then fill the 3-liter x times, pouring it into the 5-liter when full, and emptying the 5-liter when it's full (which you'll do y times). The solution is x=3 and y=1. The alternate solution up there is the dual formulation, 5x−3y=4 (x=2, y=2). From here, two details present themselves: one, that it's easily adaptable to other values other than 3 and 5, and two, that a solution exists only if the target value is either a factor or a multiple of the highest common factor of the container sizes (e.g. you can't get 4 liters from 6- and 3-liter containers).
- In the movie Die Hard with a Vengeance, the two main characters must solve this type of puzzle in order to disarm a bomb near a public fountain. In the original script, the bomb was a Chekhov's Gun, as the movie would end with McClane planting the bomb on the bad guy's helicopter, and upon discovery one of them asks if anyone has a four gallon jug (in the final script the bomb was used for something else entirely without the puzzle being brought up again).
- In Fermat's Room, there's a variant with two hourglasses: one of four minutes and one of seven minutes, and the goal is to time nine minutes.
- In Knights of the Old Republic on Manaan, this puzzle appears in the form of pressurized doors, where you must transfer water back and forth between a series of rooms until the left-side passage is open and you can go through. Solving it is a prerequisite for the "good" ending on that planet.
- This puzzle and several variants appear in the Professor Layton series. In Professor Layton and the Curious Village, the puzzle "Water Pitchers" asks you to divide a 16- and 9-quart/litre pitchers until they each hold 8 quarts/litres of water.
- In Zork Zero, one puzzle involves obtaining 6 "gloops" of water using a 9-gloop vial and a 4-gloop vial. Obtaining the 4-gloop vial is a multi-stage puzzle in itself.
- The Castle of Dr. Brain has a form of this with its hourglass puzzle. Measure 40 seconds with a 25 and 15-second hourglass.
- A variation of this puzzle occurs in Fatal Hearts, where you need ⅔ cup of flour but have only an 800ml cup and a 100ml cup. The puzzle's not too hard if you're good at conversions.
- A more complex version of this classic puzzle appears at the end of Sherlock Holmes Versus Arsène Lupin, where you have to measure exactly 478cc of black powder with only 250cc, 80cc and 12cc containers at your disposal. While pouring powder back and forth is an option (1x250 + 3x80 − 1x12=478), there are other ways to solve the puzzle, such as: 1x250 + 19x12=478.
- Rusty Lake Hotel has a puzzle like this, in order to pour a certain amount of water into a flask, for use in a distiller nearby.
- Appears in RuneScape, among other Stock Puzzles: During the Fremennik Trials, among the series of tasks to get a Frozen Key in Peer the Seer's portion is measuring 4 units of water from a 5-unit bucket and 3-unit jug and then pouring that amount of water into a vase.
- In Phantasmat, this puzzle appears in a chapter where you must switch on a generator. Part of the tasks involves putting a jug of 4 units of liquid on a weight, and you only have a 5-unit bottle and 3-unit bottle to get 4 units.
- Myst IV: Revelation has a slight variation of this by rerouting Tomahna's backup power from two locations on the Age, to the two gates on its hydroelectric dam.
- The final level of Tomb Raider: The Last Revelation contains a portion with two instances of the puzzle. In the first, Lara uses two waterskins, a 5-liter and a 3-liter, to pour 2 liters of water into a pitcher on a scale, opening a grate in the floor. In the second, she uses the same two waterskins to pour 4 liters of water, opening another grate.