Edit: This post has been updated with a better version of the code.
Here’s the most recent NPR puzzle:
A famous actress and a famous director share the same last name, although they are unrelated. The first name of one of these is a classic musical. The first name of the other is an anagram of a classic musical. Who are they?
Yes, this is an easy one. But hey, let’s see if a computer can solve it anyway …
So what’s the strategy, if you were solving this without a computer?
- Come up with some famous musicals that can also be a first name
- Think of a famous director/actress with that first name
- Think of another famous person with the same last name and see if it anagrams to a musical.
Well, these steps are clearly achievable with a computer.
- Get a list of famous musicals. In the solution here, we’ll take Wikipedia titles under the “Broadway musicals” category. Even though there are probably other ways to get such a list, I like this one because the method extends to just about any other category.
- Go through a list of famous names and see if any of them have a first name that’s the same as a musical.
- For each last name from the previous step, find all associated first names that anagram to a musical in the list. You can just sort the first names and the musicals to check for anagrams; I prefer to convert the words to a hash, because math.
Easy! I wrote up a solution and posted it here. If you restrict yourself to names with a score above 90, you get the following:
napoleon and selim iii => smile
oliver and emma stone => mame
I didn’t know of Selim III, but that’s on me, as he appears to be a bit of a big deal. The musicals “Napoleon” and “Smile” … eh, not so much. The other answer is better, and is of course the intended answer to the original problem.
In case you’re curious, Oliver Stone scores 100 in the Famous Names list, while Emma only scores 98. That seems about right. Sharon, whom I tried for several minutes to anagram into a musical, is also at 98.
If you remove the score restriction, you get a few other answers, including the one I tweeted about recently. The first answer is clearly the best, though.
Are there any other clear generalizations to this question that we could get a good answer to with the script?