Thursday, 23 October 2025

Exercise (1.4).5

Suppose in the Die Hard problem we have four- and five-gallon containers and we want to measure exactly three gallons. How can we do this?


We encode the scenario as follows, with $x$ the number of times we fill the four-gallon container, and $y$ the five-gallon container.

$$ 4x + 5y = 3 $$


By inspection, a solution is $x_0 = 2, y_0 = -1$. That is, we fill the four-gallon container twice and empty the five-gallon container once.

  • Fill the four-gallon container and pour it into the 5-gallon container, so it only contains 4 gallons.
  • Fill the four-gallon container again and pout it into the 5-gallon container. Since it contains 4 gallons already, only one gallon will be transferred.
  • Pour away the 5 gallons from the 5-gallon container.
  • We will be left with 3 gallons in the 4 gallon-container.


Other solutions are possible. The general solution is

$$ x = 2 + 5t \quad y = -1 - 4t $$

for any integer $t$.