Kevin Kauffman posted the following on his Facebook page:
I have two problems here, I want to see if anyone comes up with the same answers i did.
1) I have a bunch of cubes with blank sides. I have six colors of paint, how many unique painting combinations can there be using one color per side, with no 2 sides on the same cube having the same color
2) there is an infinite stretch of one lane highway, and as you know if you ever drove on a highway under construction, faster cars bunch up behind slower ones. So, on our infinite stretch we put N cars at random positions on the highway, all traveling at different, but constant speeds, all traveling in the same direction. After a long time, how many 'clumps' of cars are there, where a clump is any group of 2 or more cars?
What follows is my answer to the second problem.
Upper and Lower Bound
First, there are bounds on the solution. At "best" for the cars concerned, they can be lined up in decreasing velocity such that the fastest car is first and the slowest car is last. Assuming a car's number is proportional to its velocity, and assuming the cars are going from left to right, this would be:
This results in no car ever "clumping."
At "worst," of course, the slowest car comes first, in which case all cars line up behind it at some point, for 1 clump. The greatest number of clumps, however, is floor(n/2) - this will happen if the "best" case above sees every set of two cars swapped:
In this case (with an even number of cars), each "even" car will get stuck behind the next-slowest vehicle - and the group will be going more slowly than the group ahead of it. With an odd number of cars,
has floor(n/2) clumps with one "free" car at the front.
So my first answer was [0 floor(n/2)]. Kevin modified the problem, though, to ask for the expected number of clumps for n cars, which is decidedly different from the range of clump numbers. So here goes for finding E(n)...
Lots and Lots of LaTeX
I started by counting the total number of clumps possible for every arrangement of cars. For 0 cars or 1 car, the answer is obvious - E(0) = E(1) = 0 since there is no way to form a clump. For two cars, I decided to use some new terminology. TC(k) will be the total number of clumps for k cars. C(k,j) will be the average number of clumps for k cars assuming an arrangement where the slowest car is in the jth position. With n cars, there are n! different possible arrangements for the cars. Also, the probability of the slowest car being in the jth position is just 1 / n.
since there are (k − 1)! different arrangements for k cars once the slowest car is placed in the jth spot. Also,
So - for two cars, the slowest car is either in the first or second position. If it is in first, all other cars pile behind it and there is 1 clump; if it is in second, there are no clumps - and there is a free car in front of it. Basically, this means
In general, the average number of clumps for a particular placement of the slowest car will depend on whether the slowest car is last or not. As long as the slowest car is not last, there will always be at least one clump - the one behind the slowest car. The average number of clumps ahead of it will be the expected number of clumps for that number of cars. If the slowest car is last, the average number of clumps ahead of it will be the expected number of clumps for that many cars, and the slowest car will not cause a clump. That means that
we can write
Or, taking out the n − 1 from the 1 term in the summation,
However, note that you can also do the following for :
For the left side,
and for the right,
The Punch Line
All that is to say->
where, as listed by Wolfram, "γ is the Euler-Mascheroni constant and ψ0(x) is the digamma function."
The last part, of course, makes me think there is a much easier way of thinking about this problem...
The Much Easier Way of Thinking About This Problem
Turns out, this problem and several like it are on the Puzzles page of the XKCD Wiki. And the Discussion page for Puzzles has...discussions...about the solutions. The problem above attracted quite a bit of attention. And the easier way - or really - much much better way - of thinking about the problem came from a user named Evan, who wrote
I think I've found the easiest way to prove the harmonic series result. In the 1/n of the arrangements of n cars in which the last car is the slowest, it falls behind, so the number of clumps is the same as if the last car were not there. In the other (n-1)/n arrangements, the last car is part of a clump containing the slowest car and zero or more other cars. If there are other cars in the clump, it would exist without the final car. Thus the presence of the last car creates a clump only in the 1/(n-1) of these arrangements in which the clump consists of the last car and the slowest car. So a clump is added in ((n-1)/n)(1/(n-1)) = 1/n of the possible arrangements, and E(n) = E(n-1) + 1/n. Since E(1) = 0 we have E(n) = 1/2 + 1/3 + 1/4 + ... + 1/n for n>1. -- Evan
which I paraphrased as
Ohhhh - that's good. The only way adding a new car to the end will form a new clump is if (a) the new car is not the slowest and (b) the penultimate car was the slowest of the n-1 cars. As an aside - how does XKCDB not have math tags? DukeEgr93
Since Pundit does have math tags, I can re-write the above as saying
Meaning I could get rid of all the LaTeX stuff above, but why would I?