11
3
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 leaves 1 full bucket 3KM away from the oasis, returns back (having last drink from oasis)
- Beth brings another full bucket at the 3KM point, having 12L there now.
- Beth can advance to 6KM point and leave bucket with 4L of water in it.
- Come back to 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.
2Is this supposed to be code golf? It's tagged as a code challenge. – Dennis – 2017-01-06T01:44:45.457
Yes, it's code-golf, I added the tag. Come up with a correct formula and express it through the code. – romaninsh – 2017-01-06T01:46:22.413
1I think it's worth expanding on step 1. It wasn't clear to me at first how Beth could travel 6km with only 5 liters of water: she drinks only after each km she travels, and at the last one she's at the oasis. – xnor – 2017-01-06T07:14:02.383
1Could you give a test-case, in the way that a program would output it? – Pavel – 2017-01-06T08:17:47.547
Edited the question to address both points. – romaninsh – 2017-01-06T13:24:16.403
@romaninsh Please add some more testcases, and since you stated you do have a formula, please provide that too. – flawr – 2017-01-06T17:12:38.700
Can Beth pour water from one bucket into another – pppery – 2017-01-07T00:31:38.570
@ppperry "Moving water between the buckets is permitted." – insertusernamehere – 2017-01-07T11:08:44.677
If Beth leaves a 5L bucket at the 5.5Km point she would have 9.5L of water on her return allowing her to reach 16Km. – Neil – 2017-01-07T12:17:39.757
Neil you are on to something interesting here ;) – romaninsh – 2017-01-07T15:11:30.650
Isn't that actually this problem: "The Jeep Problem With Complete Refilling"?
– insertusernamehere – 2017-01-07T17:13:11.987If I've understood correctly, the subtly different version where Beth has to drink continually as she walks has the solution d = xy (x <= 3) d = (x + 3) y / 2 (x >= 3). – Neil – 2017-01-07T17:25:27.273
Well yeah. The fact she can carry only 2 buckets means she can place one full bucket at some point while she would use the other one to get back to previous base. I am not an expert in those puzzles, I just remember this one from my school days and I thought I'd share. – romaninsh – 2017-01-07T17:27:07.670