The best-known pangram — a sentence containing every letter of the alphabet — is probably
There are lots of others of course. If you write like James Joyce, there are probably an infinite number of others. The point is to be short, and one of the shortest, with only 29 letters (!), even has a geological flavour:
I know what you're thinking: Cool, but what's the shortest set of mineral names that uses all the letters of the alphabet? What logophiliac geologist would not wonder the same thing?
Well, we posed this question in the most recent "Riddle me this" segment on the Undersampled Radio podcast. This blog post is my solution.
The set cover problem
Finding pangrams in a list of words amounts to solving the classical set cover problem:
Our universe is the alphabet, and our \(S\) is the list of \(m\) mineral names. There is a slight twist in our case: the set cover problem wants the smallest subset of \(S\) — the fewest members. But in this problem, I suspect there are several 4-word solutions (judging from my experiments), so I want the smallest total size of the members of the subset. That is, I want the fewest total letters in the solution.
The set cover problem was shown to be NP-complete in 1972. What does this mean? It means that it's easy to tell if you have an answer (do you have all the letters of the alphabet?), but the only way to arrive at a solution is — to oversimplify massively — by brute force. (If you're interested in this stuff, this edition of the BBC's In Our Time is one of the best intros to P vs NP and complexity theory that I know of.)
Anyway, the point is that if we find a better way than brute force to solve this problem, then we need to write a paper about it immediately, claim our prize, collect our turkey, then move to a sunny tax haven with good water and double-digit elevation.
So, this could take a while: there are over 95 billion ways to draw 3 words from my list of 4600 mineral names. If we need 4 minerals, there are 400 trillion combinations... and a quick calculation suggests that my laptop will take a little over 50 years to check all the combinations.
Can't we speed it up a bit?
Brute force is one thing, but we don't need to be brutish about it. Maybe we can think of some strategies to give ourselves a decent chance:
- The list is alphabetically sorted, so randomize the list before searching. (I did this.)
- Guess some 'useful' minerals and ensure that you get to them. (I did this too, with quartz.)
- Check there are at least 26 letters in the candidate words, and (if it's only records we care about) no more than 44, because I have a solution with 45 letters (see below).
- We could sort the list into word length order. That way we search shorter things first, so we should get shorter lists (which we want) earlier.
- My solution does not depend much on Python's set type. Maybe we could do more with set theory.
- Before inspecting the last word in each list, we could make sure it contains at least one letter that's so far missing.
So far, the best solution I've come up with so far has 45 letters, so there's plenty of room for improvement:
'quartz', 'kvanefjeldite', 'abswurmbachite', 'pyroxmangite'
My solution is in this Jupyter Notebook. Please put me out of my misery by improving on it.