Beta

Taking the wagon to market

Description:

THE PROBLEM:

You are a farmer with a large barrel, which you want to take to the market to sell. Unfortunately, the market is 100 miles away from your farm, and the barrel is too heavy for you to move by yourself. You do however have a camel, which you can use to carry the barrel for you.

Here's the catch: the camel only has 100 energy. Every mile that it walks while carrying the barrel, the camel will lose barrel amount of energy. Additionally, every mile that it walks while NOT carrying the barrel it will lose no_barrel amount of energy.

For example, if barrel = 2 and no_barrel = 0.4 the camel will lose 20 energy walking 10 miles with the barrel, or 4 energy walking 10 miles without the barrel.

You have a strategy for dealing with this problem. You will make the camel carry the barrel until it has just enough energy to make the return journey home. Then, you will leave the barrel at that spot, go back to the farm with the camel and allow it to regain its full 100 energy there. The following day, you will lead the camel back to the spot where you left the barrel overnight, make it carry it a little further, and then return home again. You repeat this step until you finally reach the market with the barrel and the camel. Remember that the camel also needs to return home to the farm after delivering the barrel!

THE TASK:

In this Kata, your task is to work out how far the camel travels in total, rounded to the nearest mile!

Some rules for simplicity:

0 < no_barrel < 0.5
no_barrel < barrel

EXAMPLE:

Starting values: no_barrel = 0.4, barrel = 2

Day 1:

barrel moved 41.666 miles, barrel position 41.666 miles

total distance camel travelled: 83.333 miles

Day 2:

barrel moved 27.777 miles, barrel position 69.444 miles

total distance camel travelled: 222.222

Day 3:

barrel moved 18.519 miles, barrel position 87.963 miles

total distance camel travelled: 398.148

Day 4:

barrel moved 12.037 miles, barrel position 100 miles

total distance camel travelled: 598.148 (rounded to 598 miles)

Remember, we have included the camel's final return journey of 100 miles. It is also worth remembering that the camel does not need to go any distance beyond the market, and that it may have a little energy left over when it finally returns home at the end.

Puzzles

Stats:

CreatedMar 6, 2020
PublishedMar 6, 2020
Warriors Trained24
Total Skips2
Total Code Submissions8
Total Times Completed6
Elixir Completions6
Total Stars1
% of votes with a positive feedback rating50% of 4
Total "Very Satisfied" Votes1
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments3
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • edchancellor Avatar
Ad