In 'Solving “Water buckets” Problem Using Scala' Biju Kunjummen presented a Scala program to solve this puzzle:
You have a 12-gallon bucket, an 8-gallon bucket and a 5-gallon bucket. The 12-gallon bucket is full of water and the other two are empty. Without using any additional water (or buckets) how can you divide the twelve gallons of water equally so that two of the three buckets have exactly 6 gallons of water in them?
This is a C++ solution. For explanation of algorithm see my blog