[not original but a fun problem - credit to TM Campbell]
The Chief Mathematician was disappointed at the mathematicians' picnic to find that the picnic tables were not evenly spaced. In fact, they were separated by distances of , , , , and feet, in that order. He ordered that the tables be repositioned at equal spacing, with the minimum of total movement so as to minimise the risk of upsetting the lunch. How was this done?
If the minimum total movement (in feet) required is , give as your answer.
For example, if the first table is moved feet to the left, and the second table feet to the right, this contributes feet to the total movement.
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.
This fairly innocuous looking problem has two major difficulties: the function we have to minimise is a sum of modulus functions; these aren't differentiable, so we can't use calculus, and they're not linear, so we can't use linear programming (except...see below). Also, the constraint is quite unusual.
Warning - long solution ahead! If there's a quicker way, please let me know.
The first thing to observe is that the sizes of the individual tables don't matter - only the gaps are important, so we can treat the tables themselves as having zero length.
Say we measure distances from the first table; let the initial position of the i th table be P i ; so P 1 = 0 , P 2 = 1 2 , P 3 = 2 0 , P 4 = 2 5 , P 5 = 3 5 , P 6 = 4 1 .
If table i is moved d i feet to the right (a move to the left corresponding to a negative value), the function we need to minimise is i = 1 ∑ 6 ∣ d i ∣
If Q i = P i + d i denotes the final position of the i th table, then the constraint is that the Q i form an arithmetic progression; that is Q i = A + i D for some A , D . Alternatively, we can write five constraints as Q i + 1 − Q i = D
Approach 1: linear programming
I mentioned above that the objective function is not linear. However, there is a very cunning trick we can use: instead of using the d i as variables, let table i be moved l i feet to the left and r i feet to the right, with both these values non-negative. Then our objective function becomes i = 1 ∑ 6 l i + r i The trick here is that by minimising this function, we force either l i or r i (or both) to be zero. There's no risk of linear programming returning, say, l i = 5 and r i = 2 because the overall effect is the same as l i = 3 , r i = 0 , but with a larger contribution to the objective function.
The constraints can be written as l i ≥ 0 , r i ≥ 0 , D ≥ 0 and P i + 1 + r i + 1 − l i + 1 − ( P i + r i − l i ) = D
This is now completely linear, so we can use (say) the simplex algorithm to solve it; the result is a total distance moved of 8 . 2 5 feet, giving the answer 8 2 5 0 .
Approach 2: parameter space
What does the set of all possible valid final arrangements look like? How can we parameterise it?
The final positions of the tables must be in arithmetic progression. Although we have 6 tables, there are only 2 degrees of freedom. For example, we could fully specify the final positions of the tables by giving the position of any one table, and the size of the gap between them. Or (as I'll do here), we can specify how much we move the two outermost tables; we know the remaining tables are spaced equally between them.
Let's say we move the first table a distance x to the right, and the last table a distance y to the right. If we decide we want to move them to the left, we just change the signs of these quantities as appropriate; if we want them to stay still, we set the distances to zero.
We can now visualise the parameter space as an ( x , y ) coordinate system. For each point ( x , y ) , we can work out the new positions of all the tables (knowing that they're equally spaced), and calculate how far each table has moved. The total of these distances moved is the function we want to minimise.
As an example, say we don't move the end tables at all; we just adjust the middle tables so that they're spaced evenly.
Total movement: 1 0 (this is, incidentally, not bad, and almost certainly what I'd do in practice!)
We can define a function f ( x , y ) to be the total movement of all the tables corresponding to the point ( x , y ) of our parameter space. In this case, we have found that f ( 0 , 0 ) = 1 0 .
What does this function look like? If we plotted it on the z -axis above the ( x , y ) parameter space, we would see a surface made up of sections of planes (sort of polyhedral, but the outer planes are not bounded). This is the equivalent of the familiar V-shaped plots of modulus functions in 2D.
With a bit of thought, we can see that (at least) one of the vertices of this polyhedral surface must be the lowest point (ie, the point that represents the optimal solution). It's possible that a whole edge, or a whole face of the surface is optimal, but by checking the vertices we guarantee finding the minimum value of the function.
The edges of the surface correspond to fixing a particular table (ie a zero contribution to the total movement from that table). The vertices - where the edges meet - correspond to fixing two tables.
So, with this intuition, we now know that the optimal solution will come from picking two tables to leave in place, and moving the others. With six tables in total, there are only 1 5 pairs of tables to check; this is actually somewhat quicker than the simplex algorithm above.
Trying all possible pairs, we find the optimum occurs when we keep tables 2 and 6 in their original positions:
and again we have a total distance moved of 8 . 2 5 feet.