You have 12 liters of apple juice in a 12 liters bucket and you want to share it with your best friend. But you have an empty 8-liter and an empty 5-liter bottle.
How do you split the apple juice in half?
Source: fekraneh.ir
You have 12 liters of apple juice in a 12 liters bucket and you want to share it with your best friend. But you have an empty 8-liter and an empty 5-liter bottle.
How do you split the apple juice in half?
Source: fekraneh.ir
Here is a general algorithm. A and B are the 5 and 8 liter bottles. The 12-liter bottle is the juice reserve. The capacity is irrelevant.
Depending on which bottle is A and which is B, you get a 7-step or a 18-step solution. (Or one less step if you accept solutions where one part is split in 2 bottles)
This, by the way, works for every 2-bucket problem. If it has a solution.
PS: I realized the capacity of the 12-bottle is not irrelevant since it is less than 8+5. It can be used for a 10-move solution.
Here is a possible solution:
STEP 0 1 2 3 4 5 6 7
-------------------------------------------
5-Liter 0 0 5 0 3 3 5 0
8-Liter 0 8 3 3 0 8 6 6
12-Liter 12 4 4 9 9 1 1 6
First pour the water in the bucket into the 8-litre bottle, then 4 litres remain in the former.
Step 2: pour the water in the 8-litre bottle into the 5-litre bottle, now there'll be 4 litres in the bucket, 3 in the 8-litre bottle and 5 in the remaining one.
Then add the water in the 5-litre bottle to the bucket - there'll be 9 litres in the latter and 3 in the 8-litre one.
Now pour the water in the 8-litre bottle into the 5-litre bottle and fill the 8-litre bottle with the 12-litre bottle - there'll be 1 litres in the bucket, 8-litre one will be full and 3 litres will be in the 5-litre one.
Finally fill the 5-litre bottle using the 8-litre one and pour all the water in the 5-litre bottle into the bucket.