This week's challenge comes from listener Matthew Leal of San Francisco. Write down the name of a country plus its capital, one after the other. Hidden in consecutive letters inside this is the name of a film that won an Academy Award for Best Picture. Name the country, capital, and film.
Okay, let's inventory our needs for this puzzle:
- CC: a list of countries and capitals;
- BP: a list of Best Picture winners;
As usual, we'll need to clean and format our data a little to make it suitable for the kind of comparison we're doing. For each country, capital, and movie, we'll want to lowercase all letters, remove any non-letters (spaces, apostrophes, hyphens). I also like to use a python package called Slugify for this kind of task; slugify converts unicode letters into their nearest ASCII equivalent. This means that "Curaçao" becomes "Curacao", etc. We'll also want to concatenate the country+capital, with no spaces, and we'll want to do the same for all the words in the movie title.
For example:
- Domincican Republic, Santo Domingo --> dominicanrepublicsantodomingo
- Côte d'Ivoire, Yamoussoukro --> cotedivoireyamoussoukro
- Ben-Hur --> benhur
- The Shape of Water --> theshapeofwater
Then we simply need to iterate through these lists and see if we find a movie title inside a country+capital string.
- for cstring in countries_capitals:
- for mstring in movies:
- if mstring in cstring:
- print(cstring)
- print(mstring)
And that's how we solve this puzzle!
Actually, this is a relatively easy one to solve without any scripting. If you just skim through a list of countries and their capitals, you're likely to spot the name of the movie. But it's fun to script a solution just for fun, so I'm trying it with Python as well.
Good luck! I'll post my script and solution on Friday, after the NPR submission deadline has passed.
--Levi King
No comments:
Post a Comment