A merchant from Baghdad who met the needs of the pilgrims who crossed the desert had to face on one occasion the intriguing problem that we detail below.

He was visited by the guide of a caravan that wished to acquire a supply of wine and water. Presenting three ten-gallon containers of wine, he asked the merchant for 3 gallons of wine in the first container, three gallons of water in the second and three of wine and three of water mixed in the third, and he also asked for three gallons of water to each of its thirteen camels.

As water and wine, according to Eastern custom, are only sold in even quantities of gallons, the merchant had only a measure of two gallons and another of four to carry out a task that presented him with unexpected difficulties.

However, without resorting to any trick or trickery, or any strange device for problems of this type, he extracted water from a barrel filled with 63 gallons and wine from a barrel filled with 31 and 1/2 gallons in the required proportions Without any waste.

What is the least amount of manipulations in which the task can be carried out, counting as a manipulation each time the liquid is extracted from one container to pour it into another?

#### Solution

The minimum number of manipulations needed to meet your client's requirements is 506!.

Let's see the process:

The number at the end of each paragraph denotes the number of manipulations in that paragraph.

The barrel contains 63 gallons of water and the barrel 31 gallons and 1/2 of wine. First of all we have to fill the three 10 gallon bottles with wine, pouring the remaining 1 gallon and 1/2 in the measure of 2 gallons, thus emptying the barrel (4 manipulations).

Using the 4 gallon measure, fill the barrel with the barrel, leaving 1/2 gallon in the 4 gallon measure. Give this 1/2 gallon to camel No. 1. Using the 4 gallon measure pour 28 gallons of water from the barrel to the barrel. Pour 1 gallon and 1/2 of wine from the size of 2 gallons to that of 4 gallons. Pour 2 gallons of water from the barrel to the extent of 2 gallons and return them to the barrel. Withdraw the remaining 1 gallon and 1/2 gallon of water from the barrel with the 2 gallon measurement and give it to the camel No. 2. Pour 1 gallon and 1/2 of the 4 gallon wine into the 2 gallon (37 manipulations) .

Repeat all operations of the last paragraph 11 times more, so that 6 camels receive 2 times 1/2 gallon of water and another 6 camels 2 times 1 gallon and 1/2. But in the tenth and eleventh repetition, instead of returning the 2 gallons to the barrel, give them to any 2 of the camels that have received only 2 times 1/2 gallon. 8 camels have now received 3 gallons each and 4 camels 1 gallon each and 35 gallons of water will remain in the barrel (407 manipulations).

Pass the water from the barrel to the barrel with the measurement of 4 gallons, to fill it and give the remaining 1/2 gallon to the No. 13 camel. Remove 3 gallons from the barrel with the measurement of 4 gallons (18 manipulations).

Put all the wine back in the barrel. Empty the barrel into three 10 gallon bottles and remove the remaining 1 gallon and 1/2 with the 2 gallon measurement. Pour the contents of the three bottles back into the barrel and pour 1 gallon and 1/2 the size of 2 gallons into bottle No. 1 (12 manipulations).

Fill the 2 gallon measurement with that of 4 gallons, leaving 1 gallon in the latter. Fill the barrel with the measurement of 2 gallons and give the remaining 1/2 gallon to camel No. 13. Give 2 gallons to each of the remaining 5 camels and you will have finished serving the camels (13 manipulations).

Fill the two empty bottles with water from the barrel and pour the remaining 1 gallon and 1/2 into the No. 1 bottle. Return the contents of the bottles Nºs to the barrel. 2 and 3 (5 manipulations).

Pour 1 gallon of the 4 gallon measure in the No. 2 bottle. Put 6 gallons of wine in the No. 3 bottle, using the 2 gallon and the 4 gallon measure. Pass the 1 gallon of the No. 2 bottle to the 4 gallon measure and fill the latter with the wine from the No. 3 bottle. Pour the contents of the 4 gallon measure into the No. 2 bottle. Remove 2 gallons of water from the barrel and pour them into bottle # 2 (10 manipulations).

The 13 camels have already received 3 gallons of water each, one of the 10 gallon bottles contains 3 gallons of water, another 3 gallons of wine and the third 3 gallons of wine and 3 of water mixed. The barrel contains 25 gallons and 1/2 of wine and the barrel 18 gallons of water. Total number of manipulations: 506.