The Holiday Riddler from 538 focused on a grumpy elf:
In Santa’s workshop, elves make toys during a shift each day. On the overhead radio, Christmas music plays, with a program randomly selecting songs from a large playlist.
During any given shift, the elves hear 100 songs. A cranky elf named Cranky has taken to throwing snowballs at everyone if he hears the same song twice. This has happened during about half of the shifts. One day, a mathematically inclined elf named Mathy tires of Cranky’s sodden outbursts. So Mathy decides to use what he knows to figure out how large Santa’s playlist actually is.
Help Mathy out: How large is Santa’s playlist?
I missed the deadline to win, but I figured it was still worth writing up my solution.
The short version: It depends on how long the elves have been observing Cranky, but there are probably somewhere between 5,000 and 10,000 songs in Santa’s playlist, with those bounds narrowing as more days are observed. If 100 days were observed (with a repeat on 50 days), the playlist is likely between 5,598 and 9,889 songs. If 364 days were observed (with a repeat on 182 days), the playlist is likely between 6,250 and 8,401 songs. If only 10 days were observed (with a repeat on 5 days), the playlist is likely between 3,941 and 28,709 songs.
If the true repeat rate is as close to 50% as possible (e.g., a near infinite number of observations), the playlist is likely either 7,174 or 7,175 songs.
For this solution, I constructed a prior distribution based on iTunes library sizes, calculated the probability of a repeat on a given day for playlist sizes from 100 to 180,660 songs, found the probability of observing a repeat on exactly half of all shifts for even numbers of shifts from 4 to 366, then calculated the posterior distribution for each number of shifts. For the exact case, I selected the number of songs just above and just below 50% chance of having a repeat.
(This assumes that “about half of the shifts” is interpretted as exactly half.)
I could have just selected an uninformative prior (e.g., uniform over all of the number of songs that I tested), but that seemed boring. Instead, I sought out two pieces of information: how many Christmas songs are there and how large is a “large playlist?”
As of 2014, there were 180,660 unique Christmas recordings on Spotify according to an analysis by Aaron Daubman. I can only find the write up by Paul Lamere, so I can’t determine how many of those are unique songs compared to unique recordings (e.g., Silent Night has been recorded by 7,406 artists, each of which appears to count towards that 180,660). In fact, if we count each publishing of a recording (e.g., the 2,196 albums with Bing Crosby’s recording of White Christmas), there are 914,047 Christmas tracks. So, we will assume that Cranky can tell the difference between artists but not tracks and place an upper bound for the playlist at 180,660.
In addition, we can look at what constitutes a “large playlist” as defined in the question. Streaming has made this harder, as most music listeners no longer own the music they listen to, so a playlist size is hard to identify. We can, however, reach back to the time when iTunes dominated for serious music lovers, and use data from some of the tools used by those with large libraries to manage their music.
In an interview with Cult of Mac in 2011, the CEO of TuneUp – an iTunes add-on used by some serious users with large libraries – said that the average library was 3,000 songs with the largest at 100,000. We can use this to construct a skewed distribution by using the normal density curve for the log-transformed values with mean of 3,000 and standard deviation of 10. This gives a prior distribution that looks like this:
Note that the distribution is truncated at 100 songs (below this, there will always be a repeat) and 180,660 songs (the number of Christmas songs identified above). The distribution is a bit easier to see on a log-scale (which I will be using for the rest of the plots as well)
The likelihood distribution falls into two pieces:
For the first part, I took the same approach as Laurent Lessard. For any number of songs, the probability of a repeat in any single shift is:
From this, we can show that the probability crosses 50% between 7,174 and 7,175 songs (the same point as Laurent Lessard found – hooray for not making a mistake).
| Number of songs | Probability of a repeat |
|---|---|
| 7174 | 0.5000284 |
| 7175 | 0.4999798 |
However, this is only part of the calculation. If there were only 10 days observed, it is pretty likely to get 5 days with a repeat from a relatively large range of playlist sizes:
if we observed 100 shifts instead, the probability drops a fair bit and the range narrows:
We can construct a similar curve for every evaluated number of shifts
We can then apply Bayes rule to determine the posterior probability of each playlist size for a given number of shifts.
if we observed 100 shifts instead:
We can plot the overlapping posteriors just like we did the likelihoods:
However, the distributions now overlap because the area under each is 1 (the areas in the likelihoods were smaller for larger numbers of shifts because getting a repeat in exactly half of shifts is less likely if there are more shifts).
We can clean things up a bit by plotting the cumulatative posterior instead:
However, the metric of interest – the middle 95% of values – is still a bit harder to parse out. Instead, we can plot the lower and upper bounds for the middle 95% of the posterior distributions for each number of shifts:
As we can see, with a very small number of shifts observed, the number of songs in the playlist could plausibly range by quite a bit. We can filter out cases with less than 10 shifts observed to get a better picture:
We can also plot the number of songs on a log scale to clarify the assymmetries between the lower and upper bounds.
If 100 days were observed (with a repeat on 50 days), the playlist is likely between 5,598 and 9,889 songs. If 364 days were observed (with a repeat on 182 days), the playlist is likely between 6,250 and 8,401 songs.
This gives us the best picture of our posteriors that we can expect from the information given.
Here are the bounds in table format: