Appleville to Bananaville transportation

Logic Level 3

You have been given the task of transporting 3,000 apples 1,000 miles from Appleland to Bananaville. Your truck can carry 1,000 apples at a time. Every time you travel a mile towards Bananaville you must pay a tax of 1 apple but you pay nothing when going in the other direction (towards Appleland).

What is highest number of apples you can get to Bananaville?


The answer is 833.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Ivan Koswara
May 19, 2016

Note: This is not a perfect solution yet. Just some thoughts.

I assume that we can't divide the apples, so that you must always travel an integral number of miles.

Suppose we traverse the n n -th mile for a n a_n times (in the forward direction). Then we lose i = 1 1000 a i \sum_{i=1}^{1000} a_i apples just because we made all those trips, or in other words, we can get 3000 i = 1 1000 a i 3000 - \sum_{i=1}^{1000} a_i apples through... can we? There's another restriction, the "1000 apples at a time" limit.

If we traverse the n n -th mile for a n a_n times, then we can only get at most 1000 a n 1000a_n apples past the n n -th mile (and a n a_n of them are gone for the cost of the n n -th mile). In other words, the number of apples we can get through is at most 1000 a n i = n 1000 a i 1000a_n - \sum_{i=n}^{1000} a_i apples.

I think these are all the restrictions. The number of apples we can get through is bounded above by the minimum of all of these; that is, min { 3000 i = 1 1000 a i } { 1000 a n i = n 1000 a i 1 n 1000 } \min \{3000 - \sum_{i=1}^{1000} a_i\} \cup \{1000a_n - \sum_{i=n}^{1000} a_i | 1 \le n \le 1000\} . For the sake of brevity, let s 0 = 3000 i = 1 1000 a i , s n = 1000 a n i = n 1000 a i s_0 = 3000 - \sum_{i=1}^{1000} a_i, s_n = 1000a_n - \sum_{i=n}^{1000} a_i , so the answer is bounded by min { s i } \min \{s_i\} . But there are 1000 variables to take care of; can we simplify it?

Of course we can. Clearly we need to have all a i a_i 's to be at least 1. It also seems that no a i a_i needs to be more than 3. And finally, it's pretty clear that the sequence of a i a_i 's is non-increasing; if we traverse the n n -th mile for a n a_n times, we don't need to traverse the n + 1 n+1 -th mile for more than a n a_n times, since all the load that's present can be carried in just a n a_n trips past the n + 1 n+1 -th mile. Thus, we can actually simplify the expression to just two variables. Let p , q p, q be integers satisfying 1 p q 1000 1 \le p \le q \le 1000 such that a 1 = a 2 = = a p = 3 a_1 = a_2 = \ldots = a_p = 3 , a p + 1 = a p + 2 = = a q = 2 a_{p+1} = a_{p+2} = \ldots = a_q = 2 , and a q + 1 = a q + 2 = = a 1000 = 1 a_{q+1} = a_{q+2} = \ldots = a_{1000} = 1 . Now most of the s i s_i 's are redundant (if a n = a n + 1 a_n = a_{n+1} , then s n s n + 1 s_n \le s_{n+1} ), so s n + 1 s_{n+1} doesn't matter. The only important terms are s 1 , s p + 1 , s q + 1 s_1, s_{p+1}, s_{q+1} .

  • s 1 = 1000 a 1 i = 1 1000 a i = 3000 ( 3 p + 2 ( q p ) + 1 ( 1000 q ) ) = 2000 p q s_1 = 1000a_1 - \sum_{i=1}^{1000} a_i = 3000 - (3p + 2(q-p) + 1(1000-q)) = 2000 - p - q
  • s p + 1 = 1000 a p + 1 i = p + 1 1000 a i = 2000 ( 2 ( q p ) + 1 ( 1000 q ) ) = 1000 + 2 p q s_{p+1} = 1000a_{p+1} - \sum_{i=p+1}^{1000} a_i = 2000 - (2(q-p) + 1(1000-q)) = 1000 + 2p - q
  • s q + 1 = 1000 a q + 1 i = q + 1 1000 a i = 1000 ( 1 ( 1000 q ) ) = q s_{q+1} = 1000a_{q+1} - \sum_{i=q+1}^{1000} a_i = 1000 - (1(1000-q)) = q

Thus we're looking for p , q p,q to maximize the value of min { 2000 p q , 1000 + 2 p q , q } \min \{2000-p-q, 1000+2p-q, q\} .

This is pretty much an integer programming problem. Had it been a normal real optimization problem, finding the best p , q p,q would be as easy as equating the three expressions together (there are two variables and there will be two equations, so there should be a unique solution--and indeed there is, p = 1000 3 , q = 2500 3 p = \frac{1000}{3}, q = \frac{2500}{3} , with the value of the expression being 2500 3 \frac{2500}{3} ). But integer programming cannot be solved that way... can it?

As it turns out, this particular case can be solved approximately that way. We did get the solution p = 1000 3 , q = 2500 3 p = \frac{1000}{3}, q = \frac{2500}{3} , so we try the points around it, p = 333 or 334 p = 333 \text{ or } 334 and q = 833 or 834 q = 833 \text{ or } 834 . We find that q = 833 q = 833 (and either choice of p p ) gives the value of the expression being 833, and since we know the real optimization problem has value 2500 3 < 834 \frac{2500}{3} < 834 , we know for sure that our 833 is optimal for our integer programming case.

So we know that the number of apples that we can get through is at most 833. Can we achieve this? As it turns out, yes, we can:

  • Make 3 trips of 333 miles each, dumping the remaining 667 apples at the 333th mile mark.
  • Make 2 trips of 500 miles each, dumping the remaining 500 apples at the 833th mile mark. (We leave 1 apple.)
  • Make a trip of 167 miles, finishing with 833 apples remaining.

This corresponds precisely with p = 333 , q = 833 p = 333, q = 833 . Thus the answer should be 833 . Note that this is "should be" because I'm still not very certain about the italicized parts above.

Moderator note:

Good clear explanation.

It helps to consider the relaxed constraint (of real numbers) and determine the upper bound, and then find an integer solution which achieves it.

Brilliant solution

Prince Loomba - 5 years ago

I think your solution is correct but that you may be uncertain about it because you took a more analytical and pretty much atomistic approach and as such considered abstractly it is not articulate enough what actually makes the number of apples lost to be minimal while a little bit more synthetic approach would work better in making things clear.

The problem can be formulated for initial purposes (though incomplete) as how to transport a number of apples over a distance such that under the restraint of taxes the number of lost apples to be minimal which arrives straightforward at the observation that in order to minimize the number of lost apples the biggest number possible of apples should travel the least amount of distance. By this observation is also immediate that the least number of apples lost depends on maximizing the number of apples which can be carried together for the holistically considered complete distance because for a number of n apples which can be carried together the tax for the distance traveled will be the same this maximal number being important and from this initial settings of the problem (which are pretty much immediate but should be told for the purposes of introducing the problem in it's synthetic terms) it can be finally derived that the synthetic formulation of the problem is how to carry the apples over that distance such that the number of apples that can be carried together having largest amount of distance in common should be maximal under the constraint of the carry limit which can be noted as L. Or , in other words implies how many apples can be carried together over the maximal distance from the complete distance being that the maximal number is found under the limits of 1000 apples that can be carried one at a time and therefore can be said articulate enough that restrains the maximal number of common apples which are carried formulation from which thinking in this terms , it is pretty easy to consider the problem and as such take a direct representation of the optimal strategy for which this will work and also understand by principle and a little bit more concretely than by using equations to derive it why this is minimal which nonetheless is what must be assured and therefore what should be of interest here anyways since that is what the problem asks. By considering how does L restrain the distance traveled in common by a number of apples it can be said that from the initial point of the distance at which it is started there should be a number of transports of L apples until some point of the distance at which if I don't stop and load the truck at maximum the number of lost apples will be greater than if I stop and load it at L. Considering therefore finding what is that minimal value is therefore what is important and the reasoning pretty much seems to be greedy for the entire problem , that is finding the most efficient value for a step does maximize the value of the complete number of steps. So for finding that first point at which the truck should be stopped because otherwise I will lose apples observe that it depends on L also. This because in order to be a difference of lost apples if I don't stop at a point than if I stop as arriving at a point there will remain N - L* p apples (as will be lost L*p) it should be possible for stopping and loading for the remaining apples to be traveled in less than L trips as it would be if I wouldn't stop and load because otherwise the number of apples lost will remain constant for those cases since the number of lost apples will be done for both cases in L trips and not in L-1 trips and L trips. So the point at which I stop should be in this particular case the one in which I arrive at the possibility of transporting 2000 apples but in order to minimize the number of lost apples due to the other variable which is a priori considered (tax per mile for apples) the least point which has 2000 apples. That point is arrived at calculating in a simple concrete way and assures is the best point that can be achieved such that the number of apples that will travel in common from there will be the greatest and therefore assures by thinking in the problems terms of optimizing things. The rest is greedy as I said , you just have to find the best point for 2000 apples and so on. Observe that by thinking in the problems terms and taking therefore a synthetic approach here rather than an analytic approach can clarify things and assure if the reasoning is correct and in more or less a way the source of your italicized so say things of which you are not clear are more the result of that lack of synthesis and in particular maybe such optimization problems would suppose this type of concrete approaches maybe but anyways a solution as yours is really good I think oh and a beautiful problem.

A A - 5 years ago
Prince Loomba
May 15, 2016

Answer: 833 apples.

Step one: First you want to make 3 trips of 1,000 apples 333 miles. You will be left with 2,001 apples and 667 miles to go. Step two: Next you want to take 2 trips of 1,000 apples 500 miles. You will be left with 1,000 apples and 167 miles to go (you have to leave an apple behind). Step three: Finally, you travel the last 167 miles with one load of 1,000 apples and are left with 833 apples in Bananaville

Rushikesh Jogdand
May 19, 2016

You should load the truck as much as possible to lose minimum number of apples.

Rest calculation can be done tediously or lazily like

1
2
3
4
5
6
7
apples=3000
for mile in range(1,1001):
    if apples%1000==0:
        apples-=apples/1000
    else:
        apples-=apples//1000+1
print (apples)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...