Skip to main content

Solution in \$n\$ bananas, where \$n\$ is the number of bananas you own, and \$c\$ is the number of bananas the camel can carry.

Solution:

  • For bananas \$0 \rightarrow c\$ the cost to move a banana is \$1\$ banana per km.
  • For bananas \$c+1 \rightarrow 2c\$, the cost to move a banana is \$3\$ bananas per km.
  • For bananas \$2c+1 \rightarrow 3c\$, the cost to move a banana is \$5\$ bananas per km.
  • etc.

This is because, if the camel moves the bananas 1 km at a time, he needs to make two trips for each load beyond his current capacity.

Define \$t = \lfloor\frac{n}{c}\rfloor\$ Therefore, the total number of miles the camel can reach is:

$$ \left(\sum_{k=1}^{t} \frac{c}{2k - 1}\right) + \frac{(n \bmod c)}{2t+1} $$

In specific, plugging in the given \$n = 3000\$ and \$c = 1000\$, we have the camel able to travel:

$$ 1000 + 333 + 200 = 1533 \text{ miles} $$

To figure out how many bananas remain for a given distance, subtract the extra miles and multiply back at the rate given above.

For the first \$1000\$ miles, this number is just the distance beyond the total capacity \$1533 - 1000 = 533\$, or 533 miles.

durron597
  • 2.4k
  • 2
  • 21
  • 29