While similar to the other water-carrying puzzle, the unique aspects of this challenge make it entirely different.
Beth is located at an oasis in the middle of a desert. There is plenty of water in the lake, but unfortunately there are only X buckets, each of which has a capacity of Y liters of water.
Beth can carry 2 buckets in her hands, but to survive, she must drink exactly 1 liter after each kilometer she travels. She can also leave some buckets half-way (water does not evaporate).
The challenge
Figure out the formula and write the shortest solution that will work for positive integer values of X and Y and calculate the maximum distance Beth can travel from the oasis. Moving water between the buckets is permitted.
Example
X=3, Y=5
- Beth walks 3km with two full buckets. Leaves 1 full bucket behind. The other bucket now has 2L left, which is enough to get home (Beth can have the last drink from the oasis).
- She leaves with another two full buckets, arriving with 1 full, plus 2 litres in the other (12L total: 5 + 5 + 2).
- Beth can advance to 6KM point and leave bucket with 4L of water in it.
- She returns to the 3KM point. She now has exactly 2L to get back to the oasis.
- Fill up buckets and travel to 6KM point. She now has 8L of water.
- Continue all the way to 15KM point.
Answer is: 15
Input / Output
You can define X/Y directly in the code or read from input. Result could be placed in variable or output, whichever is shortest.