Sunday, June 27, 2021

US City, Japanese Food (Preview)

It's Sunday, and we all know what that means.

Let's take a crack at this week's Sunday Puzzle from NPR Puzzlemaster Will Shortz:

This week's challenge comes from listener Julia Lewis, of Fort Collins, Colo. Take the name of a major American city. Hidden inside it in consecutive letters is the name of a Japanese food. Remove that. The remaining letters can be rearranged to to spell some Mexican foods. Name the city and the foods.

 

As usual, let's start with a list of our needs:

  • C: A list of major American cities;
  • J: A list of Japanese foods;
    • This has to fit inside the city name, so it's probably short; I'm guessing it's one of these: sushi, ramen, tofu... we'll expand that if we don't get any matches;
  • M: A list of Mexican foods;
    • This target word also has to fit in the scrambled remaining letters of the city, so it also needs to be short; I'm going to start with: taco, nacho, salsa... We can expand later if needed;
So first, we'll do some text normalization on C, the list of American cities; lowercase, strip spaces and non-letters, like this:
  • St. Paul --> stpaul
  • Wilkes-Barre --> wilkesbarre
We'll also want to make sure our foods in J and M are lowercased (I don't expect spaces or non-letters anyway, as these words need to be short enough to be a substring of the city name; we might get accented characters in the Mexican list, so we'll want to strip those down to simple ASCII).

Then we'll want to do something like this:
  • for city in C:
    • for jfood in J:
      • if jfood in city:
        • print(city, jfood)
From there, it would probably be easy to "eyeball" this problem and determine what Mexican food we can spell from the remaining letters in the city name. But let's play this out fully anyway. So, we continue by removing the Japanese food substring from the city name, then iterating through our list of Mexican foods to see which we can spell with the remaining letters. We might want to be a bit flexible for the sake of handling plurals. If I'm not mistaken, Spanish plurals are always formed by adding "-s" or "-es", so we can simply check for such variations.
        • cityletters = city.replace(jfood, "")
        • cityletters = list(cityletters)
        • cityletters.sort()
        • cityletters = "".join(cityletters)  ##now we have a sorted string for easy comparison
        • for mf1 in mfoods:  ##get sorted strings for mexican food and plural variants
          • mf2 = mf1+"s"
          • mf3 = mf1+"es"
          • mf1letters = list(mf1)
          • mf2letters = list(mf2)
          • mf3letters = list(mf3)
          • mf1letters.sort()
          • mf2letters.sort()
          • mf3letters.sort()
          • m1 = "".join(mfletters)
          • m2 = "".join(mf2letters)
          • m3 = "".join(mf3letters)
          • if cityletters in [m1, m2, m3]:
            • print(city, jfood, mf)
That should do it. Good luck! I'll post my solution later this week. :-)

--Levi King

Director, anagram, film award

Welcome back to Natural Language Puzzling, the blog where we use natural language processing and linguistics to solve the Sunday Puzzle from...