Monday, 7 February 2011

Pub quiz with Mathematica

Busy with work so only a quick entry this week.

A few weeks ago, while preparing for our regular monday pub quiz, our leader in useful-only-on-monday-knowledge asked us the following question: How many capital cities start and end with the same letter? I didn't know the answer and couldn't be bothered to look at wikipedia, so I queried Mathematica instead:

Select[CountryData["Countries", "CapitalCity"][[All, 1]], (StringTake[#, 1] // ToLowerCase) === StringTake[#, -1] &]

This is putting Mathematica's online database to a good use I thought. The result turns out to be

{"AndorraLaVella", "SaintJohns", "TheSettlement", "Avarua", "Asmara", "AddisAbaba", "Accra", "SaintGeorges", "Astana", "Abuja", "Oslo", "Warsaw", "SaintDenis", "Apia", "Ankara", "Tashkent"}

So the answer is 16 - sixteen cities that start and end with the same letter. (The Settlement, by the way, is the capital of the Territory of Christmas Island - another quiz question.)

Maybe I should tell the quiz master about Mathematica or WolframAlpha. Or maybe not.

No comments:

Post a Comment