Monday, November 01, 2021

A tourist attraction and a famous author (Preview)

Alright, Puzzlers, let's get back on track with this week's Sunday Puzzle from NPR:

This week's challenge comes from Michael Shteyman of Freeland, Md. Think of a popular tourist attraction in two words. The second, fourth, and sixth letters of the second word, in order, spell the first name of a famous author. The last four letters of the first word spell the author's last name. Who is the author, and what is the tourist attraction?


Well this certainly looks do-able; it's a lot like this one we solved back in July. Let's break it down a little.

This puzzle, like probably 90% of the Sunday Puzzles we've looked at, follows the form:

transform(string_a) = string_b

In other words, we apply some transform function to string_a to yield string_b. As usual, we know what the function is; our task is to find string_a and string_b.

What do we need in order to solve this?

  • A: a list of candidates for string_a;
    • "a popular tourist attraction in two words"
    • first word must be 5 or more letters;
      • technically, it could be 4 letters, but we typically wouldn't refer to "the last four letters" of a 4 letter word, right?
    • second word must be 6 or more letters;
    • Eiffel Tower, Grand Canyon, Buckingham Palace, Times Square, etc.
  • B: a list of candidates for string_b;
    • "a famous author"
    • first name has 3 letters;
    • last name has 4 letters;
  • transform function;
    • code this in Python;
    • select letters from string_a candidates in to form string_b candidates and compare against B until we find a match;
So we need A, a list of popular tourist attractions with 2-word names. We could use a language modeling tool like SBERT or Word2Vec to come up with candidates by providing some seed terms or some sentences with blanks for the model to fill in. We've done this a few times before, like when we needed candidate words for "something birds do", for example. But "something birds do" can be difficult to list thoroughly off the top of our heads, and it's not something we can easily search the web to find a list for. A and B are both pretty straightforward, and they're things people love to make lists of! We shouldn't need to reinvent the wheel here; let's look for appropriate lists online. I suspect searching for "top 1000 authors" and "best 200 tourist attractions" or the like will turn up some lists we use.

Then we'll filter things out of the lists that don't meet the requirements for letter counts, and the script will be very short; it just needs to iterate through one list, pull out and concatenate the letters and check the resulting string against the list of authors.

OK, so that's the NLP nerd approach, but most people playing the Sunday Puzzle aren't computational lingusts, so how would one solve it without this approach? The NPR hosts always announce how many correct answers they got, and it's usually in the range of 300--2000 people. I suspect this one will be closer to 2000, because it should be fairly easy to simply start visually scanning lists of authors to find one with two names: 3, 4 (letters). There can't be many that would be on "famous" lists for US English speakers. Obviously there could be very many for, for example, Chinese (in pinyin) but those wouldn't be famous to most of our target audience. So if we had a small number of author names, we could reconstruct what we know about the tourist attraction name and try to fill in the rest. For example, let's say we have an author named May Fitz, we know the tourist attraction must look like: (_*)fitz  _m_a_y(_*), where---and please pardon my poor regex notation---we can have any number of letters before fitz, and any number of letters after _m_a_y.

Good luck out there this week! I'll be back after Thursday's NPR deadline to share my solution---scout's honor!

Levi

Saturday, September 25, 2021

Garden goods and their adjectives (Solution)

 Let's solve this week's Sunday puzzle from NPR:

This week's challenge comes from listener Rachel Cole of Oakland, Calif. Name something grown in a garden. Change the second letter, and double the third letter, to get an adjective that describes this thing. What is it?


I pretty much used my proposed approach, which you can see here.

And my solver script is available here, along with the list of "garden things" I compiled for this task.


The solution:

radish --> reddish


See you for the next Sunday Puzzle!


--Levi King

Monday, September 20, 2021

Garden goods and their adjectives (Preview)

Happy Monday, Puzzle Buddies. Let's get back on the horse with this week's Sunday Puzzle from NPR:

This week's challenge comes from listener Rachel Cole of Oakland, Calif. Name something grown in a garden. Change the second letter, and double the third letter, to get an adjective that describes this thing. What is it?

This feels very do-able. How should we approach this puzzle? Let's break it down a little:

  • something grown in a garden
    • flowers;
    • fruits and vegetables;
    • possibly something more "metaphorical", but let's assume not;
  • get an adjective
    • seems like this should be a single word, which means the something grown in a garden must also be a single word;
  • adjective that describes this thing
    • this could be quite broad, but we can start with what we know about its form;
    • must be one letter longer than the something grown in a garden string, because double the third letter;
We know this is a classic puzzle format:

transform_function(string_a) = string_b

In other words, we start with a string_a, apply the transformation described in the puzzle, and the result is string_b. As usual, we need lists of candidates for string_a and string_b. So let's spell out more clearly what we need to solve this puzzle:

  • ListA: a list of things grown in a garden;
    • I suspect we can find lists already on the web with a bit of searching;
  • ListB: a list of adjectives that can describe our something grown in a garden;
    • This is not the kind of thing we can easily find a list for, so we'll likely need to "roll our own";
    • I will likely use SBERT in "mask mode", which essentially asks the model to fill in a blank. I'll start with a short list of sentence templates, where we can insert a word from ListA, then have SBERT suggest the top 100 (or 200, etc.) most probable words to describe that word. For example:
      • The [string_a] that I grew in my garden tasted so [MASK] this year.
      • My neighbor is growing the most [MASK] [string_a] in his garden.
My plan is to start with ListA. I'll pass each of those through the SBERT model until we have a list of all the suggested adjectives for each word in ListA, i.e., the first step is to use ListA to derive ListB. Then we simply do:
  • For candidate_a in ListA:
    • for candidate_b in ListB:
      • if len(candidate_b) == len(candidate_a)+1:
        • ## first we double the third letter:
        • mod_b = candidate_b[:3]+candidate_b[2]+candidate_b[3:]
        • for letter in alphabet:
          • ## next, we change the second letter:
          • mod_b = mod_b[:1]+letter+mod_b[2:]
          • if mod_b == candidate_a:
            • print("Solution: ", candidate_a, candiate_b)
What do you think? Will it work? Do you have other ideas for approaching this? I'll see you back here after Thursday's NPR deadline with my solution. :-)

--Levi

Tuesday, September 07, 2021

Famous name & vowel change (Preview)

Here's the latest Sunday Puzzle from NPR:

This week's challenge comes from listener Derrick Niederman, of Charleston, S.C. Name a famous person (8,4). The last name is a regular uncapitalized word with a single vowel. Change that vowel to make a new word that is humorously defined by the person's first name. Who is it?

Woah, this looks like a tricky one. Let's break it down a little.

  • We need a list of famous people; no details about where the target famous person is from, or even whether he or she is living or dead.
  • We can filter this list down to persons with an 8-letter first name and 4-letter last name.
  • We expect the last name to appear in an English dictionary ("regular uncapitalized word") and have only one vowel, so we can filter accordingly for these features, too.
  • Let's call this resulting list C for "candidates". I suspect this is a fairly short list, and it's probably easiest to simply manually work through C to find the solution.
But what if we want to automate this whole puzzle and get a solution?
  • We can iterate through the names in C, generating all the 4-letter strings that result when we swap out the vowel in the last name;
    • Keep only those that appear in an English lexicon;
Again, we could stop here and intervene manually. The remaining clue is the trickiest part, after all: "a new word that is humorously defined by the person's first name." I think this means that the first name is also a regular word in English. But how do we implement "x  is humorously defined by y" in an NLP approach? I know there is research into modeling humor, but I don't know much about it or how well it works. My best bet here would be to instead rely on something like pointwise mutual information to determine how likely the x (vowel-swapped last name) is to co-occur with y (the first name). That might be worth a shot, but there's no guarantee that the "humorously defined by" clue means x and y are likely to co-occur. I'm still mulling over how to approach this puzzle, but I suspect I'll start with a list of famous people, filter it down the the candidate list C, and work on it manually from there.

Good luck, Puzzlers! I'll be back later this week with my solution.

--Levi

Saturday, September 04, 2021

Musical composition, music store purchase (Solution)

Ready for the solution to Sunday's puzzle? I started out with the approach I previously detailed, but then after searching the web for types of musical compositions, the answer leapt out at me, so I'll leave that implementation "as an exercise to the reader," as they say. :-)

Anywho, the answer to the puzzle is:

rhapsody --> rap CD

See you tomorrow for the new Sunday Puzzle!

Tuesday, August 31, 2021

Musical composition, music store purchase (Preview)

Happy Tuesday, Puzzlers. Let's get cracking on the latest Sunday Puzzle from NPR:

This week's challenge comes from listener Ari Carr, of Madison, Wis. Name a form of musical composition. If you say the word quickly, you'll name something, in two words, that you might buy in a music store. What is it?

Oh boy, this one seems a little more challenging than some of the string manipulation type puzzles we often deal with here. The good news is that we'll probably want to dip a little deeper into our NLP toolbox to solve it.

Let's break down what we need and how we might obtain it here:

  • C: a list of forms of musical composition;
    • I'm assuming this means things like concerto, aria, song, hymn, symphony.
    • How do we get this list?
      • We might find one on Wikipedia or elsewhere online; it's worth searching for.
      • We can generate one by querying Word2Vec for similar words to concerto, etc.
      • We can use BERT or SBERT in mask mode, where it fills in a blank ("[MASK]"). So we'd feed it some sentences like:
        • The prolific composer wrote more dozens of [MASK] in his lifetime.
        • I could hear an upbeat [MASK] playing softly over the stereo downstairs.
  • B: a list of things one can buy in a music store, in two words;
    • Potential pitfalls:
      • What's a "music store"? A record store? A musical instrument store? I think we'd better assume it could be either.
      • "in two words": This looks tricky, because it could mean terms like "bass guitar" but it could also include things like "a guitar".
    • We can try the Word2Vec and SBERT methods for this list too (I need to check that I can get two word terms from these tools).
  • "If you say the word (in C) quickly, you'll name something, in two words" in B.
    • This is the transformation function, like we see in about 90% of these puzzles.
    • This time, however, the transformation applies not to the spelling string but its corresponding pronunciation string. In other words, we need a pronunciation dictionary.
    • Here's an example of a past post where we've used the CMU Pronouncing Dictionary. I plan to use it again for this puzzle.
    • Regarding the "say the word quickly" bit, I plan to simply ignore the vowels in the pronunciation strings, so we'll also want a function like strip_vowels(pronunciation).
That covers the setup. Assuming we have the resources above, let's look at how we'd use them to arrive at a solution. Here's some pseudo code:
  • for x in C:
    • qp_x = pronunciation[x]  #"qp" for "quick pronunciation"
    • qp_x = strip_vowels(qp_x)
    • for y in B:
      • qp_y = pronunciation[y]
      • qp_y = strip_vowels(qp_y)
      • if qp_y == qp_x:
        • print(x, y)
It's possible we'll get some false positives here, so we'll print out any matches and see if they make sense. If we don't get any matches, we may want to relax the matching. Instead of looking for a perfect match, maybe we want something more like an edit distance. I'll probably keep it simple---check that most of the phonemes (minus vowels) in x also appears in y (and vice versa).

Good luck! I'll be back with the solution and my approach implemented in python after the Thursday deadline for submissions.

--Levi

Thursday, August 26, 2021

US city, cardinal number, ordinal number (Solution)

Ready to solve this week's Sunday Puzzle from NPR? Spoiler alert---I'll reveal my solution at the end of this post. Here's the puzzle again:


This week's challenge comes from listener Ben Austin, of Dobbs Ferry, N.Y. Take the name of a major American city. Move one of its letters three spaces later in the alphabet. Embedded in the resulting string of letters, reading left to right, is a cardinal number. Remove that number, and the remaining letters, reading left to right, spell an ordinal number. What city is it, and what are the numbers?

In my preview post, I spelled out the basic approach I'd use: iterate through city names, iterate through their letters, shifting each letter forward alphabetically three places; iterate through cardinal numbers ("one" through "one hundred") and see if it's embedded in the "shifted" city; if so, remove it and see if the remaining string is in our list of ordinal numbers. Pretty straightforward.

Well, I assembled the necessary lists and implemented my approach in a solver script, and it worked like a charm. I found and used a CSV of the 1,000 biggest cities in the USA, which you can download here. I uploaded the rest to the GitHub for this puzzle blog: cardinal numbers list, ordinal numbers list, and the solver script.

How about you? Did you solve this one?

Okay, spoilers ahead! Keep scrolling to see my answer:
































SOLUTION: 'Fort Worth' --> 'foutworth', which contains 'two'; removing 'two' yields 'fourth'

Tuesday, August 24, 2021

US city, cardinal number, ordinal number (Preview)

After giving us the last week off, Will Shortz is back with this week with a new Sunday Puzzle from NPR:

This week's challenge comes from listener Ben Austin, of Dobbs Ferry, N.Y. Take the name of a major American city. Move one of its letters three spaces later in the alphabet. Embedded in the resulting string of letters, reading left to right, is a cardinal number. Remove that number, and the remaining letters, reading left to right, spell an ordinal number. What city is it, and what are the numbers?

What do we need to solve this puzzle?
  • M: a list of major American cities;
    • Does "American" mean "USA" here? Maybe this list needs major cities from throughout North and South America;
  • C: a list of cardinal numbers spelled out in letters; probably 0-100 should be enough;
  • O: a list of ordinal numbers spelled out in letters; probably 1-100 should be enough;
  • shift_letter_3: a function that shifts a letter 3 places later in the alphabet;
First, for M, C, and O, we'll want to clean up the text:
  1. lowercase
  2. remove spaces
  3. remove non-letters
  4. convert accented characters to simple ASCII
Next, the processing is pretty simple:

  • for city in M:
    • for letter in city:
      • shifted_city = shift_letter_3(city)
      • for cardinal in C:
        • if cardinal in shifted_city:
          • short_city = shifted_city.replace(cardinal, "")
          • for ordinal in O:
            • if ordinal in short_city:
              • print("Solution: ", city, cardinal, ordinal)
That should do it. Good luck, and I'll be back after the Thursday NPR submission deadline to present my solution.

--Levi

Sunday, August 15, 2021

No Sunday Puzzle??

 Well, Puzzlers, this is odd….


The Sunday Puzzle hasn’t been posted all day, and as far as I can tell from the streaming apps, it didn’t air today either. I’m keeping my fingers crossed that it will be posted tomorrow and that all is well for our beloved Puzzlemaster Will Shortz and Weekend Edition host Lulu Garcia-Navarro. I’ll be back as soon there’s a puzzle to crack. Cheers!

Saturday, August 14, 2021

Moving vertically, horizontally (Solution)

Welcome back, Puzzlers! (Spoiler alert!) I'm back with a solution to this week's Sunday Puzzle from NPR:

This week's challenge: It comes from listener Ed Pegg Jr. Think of something that gets people moving vertically. Remove the middle two letters, and you get something that moves people horizontally. What two things are these?

In the preview post, I presented some ideas about how to approach this puzzle. In particular, I suggested using SBERT in masking mode to generate candidate words for the "something that gets people moving vertically." Well, I did manage to solve the puzzle (trampoline --> tram line), but unfortunately not by using NLP tools. The solution was sufficiently tricky that my SBERT queries did not turn up the correct candidate. I didn't upload a solver script this time, but in my SBERT queries I used verbs like ride, carry, and lift; naturally, these are not sufficiently likely to occur with trampoline.

Instead, I did this one the old fashioned way. I sat and brainstormed a list of things that move a person vertically, and eventually I landed (pun intended!) on trampoline, applied the "remove the middle two letters" transformation and recognized tram line. This was a neat puzzle. Next time I'll need to think more outside the box to ensure a language modeling tool like SBERT can turn up what I'm looking for. Probably adding a verb like bounce or launch would do the trick.

Okay, that's all for now. I'll see you tomorrow for the newest puzzle!

--Levi King

Monday, August 09, 2021

Moving vertically, horizontally (Preview)

Well Puzzlers, after a big fat fail last week (LOO --> 007; really??), I'm back with a breakdown of this week's Sunday Puzzle from NPR, and I'm feeling optimistic about this one:

This week's challenge: It comes from listener Ed Pegg Jr. Think of something that gets people moving vertically. Remove the middle two letters, and you get something that moves people horizontally. What two things are these?

Starting off, let's note some suspicious wording here: "something that gets people moving vertically". Why not just say "something that moves people vertically"? Especially given that we later have "something that moves people horizontally". This clue has me wondering if it could be something a bit tricky or figurative. Alarm clock? Coffee? A fall? None of those work, but you get the idea.

Next, we're removing the middle two letters. That tells us right away that we need an even number of letters, because a word with an odd number of letters will only have one letter in the middle. Also, obviously, we know we're dealing with letters, so no sneaky numerals like last time.

Beyond that, we need to find candidate words. This is a classic transformation(string_a) = string_b puzzle, and in this case, string_a and string_b are both open class. Moreover, I don't think we're likely to find appropriate lists already assembled online, as the classes are rather vague. Instead, I suggest we assemble our own lists of candidate words, using Word2Vec, as we did in this past puzzle, which was a favorite. This means providing a list of seed words, like elevator and balloon for the string_a, and subway and bicycle for string_b. And if that doesn't do the trick, we can use SBERT in masking mode and ask it to fill in the blanks for sentences like I rode the [MASK] to the rooftop (for string_a) and It takes 15 minutes to reach the library by [MASK] (for string_b). In assembling these lists, we can reject any word that doesn't contain an even number of characters.

Once we've assembled our lists of candidate words, we can iterate through list A, applying the transformation---removing the middle two letters. Then we can check if the resulting string appears in list B. If so, we've most likely found our string_a and string_b.

I'll be back after the NPR submission deadline (Thursdays at 3pm ET) with my solution. Good luck, Puzzlers!

Sunday, August 01, 2021

Britishisms and Heroes (Preview)

Hello, Puzzlers! Another Sunday, another Sunday Puzzle from NPR Puzzlemaster Will Shortz:

This week's challenge: This week's challenge comes from listener Chad Graham, of Philadelphia. Think of a common Britishism — a word that the British use that's not common in the U.S. Write it in all capital letters. Turn it upside-down (that is, rotate it 180 degrees). The result is a famous hero of books and movies. Who is it?

Let's begin with our usual breakdown of the puzzle. Note that it's a variation on the most common type of puzzle we see here: transform_fx(string1) = string2. In other words, we are solving for string1 and string2, where applying some transformation to string1 yields string2. In this case, we have some general "class" information about the two strings, as well as a defined transformation function. Note that the "rotate 180 degrees" part of this puzzle also occurred in a puzzle we solved just this June. However, in that case, we were rotating letter by letter, but this time, we're rotating the whole word. When we rotate a whole word, the last letter becomes the first letter (upside-down now), and vice versa. We can account for this in our solver script by reversing the order of the letters, then using our dictionary to rotate each letter in place.

As usual with this kind of puzzle, we'll want to start with a long list of candidates for string1 and a long list of candidates for string2. We'll iterate through the first list, applying the transformation to each string and checking if the resulting string appears in the second list.

So what do we need for this puzzle?

  • B: a list of "Britishisms";
  • H: a list of heroes from books and movies;
  • R180: A dictionary mapping of capital letters that can be rotated 180 degrees to form a new letter, e.g., {'M': 'W', ...};
We have a rotation dictionary (R180) we can start with, in this script. However, that puzzle called only for capital letters. In this case, the puzzle doesn't specify upper or lowercase, so we'll probably need to expand this dictionary to include lowercase. I'm not sure if the solution strings will mix upper and lowercase, but we probably want to allow for the possibility; Will can be tricky.

For B, I suspect our best bet is to spend a few minutes searching the web for such a list. Surely some anglophile has produced one on the web for other purposes already. Otherwise, we could theoretically do something like:
  1. Find/assemble a large corpus of British English;
    1. It could be a challenge to find a corpus for both written (e.g., newspaper) and spoken or vernacular English that contains exclusively British English;
  2. Find/assemble a large corpus of American English;
    1. Same challenge here;
  3. Calculate the relative frequency of each word type in the British corpus;
  4. Calculate the relative frequency of each word type in the American corpus;
  5. For each word type in the British corpus, keep the word if it is significantly more frequent in the British corpus than in the American corpus;
    1. This would take some trial and error to determine just how large the difference in frequency should be;
That certainly could be done, but it might be more than we want to take on for a hobby blog. For that reason, I think searching for an existing list of Britishisms is our best bet.

For H, we can probably find a suitable list around the web somewhere. If not we can probably get a pretty good list just by brainstorming for a few minutes. Crucially, I'm under the assumption that string1 and string2 are each single words, no spaces. So that should narrow it down a bit. We're probably also looking for fairly short strings, simply because the probability that a word will form a legitimate word when we rotate it 180 degrees is going to decrease for longer words. The fact that we're interested in a hero from books and movies may also help limit our list.

Okay, Puzzlers, I'm going to poke at this for a couple days and hopefully I'll have a solution to show for it later this week. Cheers!

--Levi King

Friday, July 30, 2021

Olympic Sports (Solution)

Hi Friends! Let's look at the latest Sunday Puzzle from NPR:

This week's challenge: It comes from the puzzlemaker and editor Peter Gordon. Think of the word for a competitor in a particular Olympic sport. It's a compound word with a hyphen in the middle. Remove the hyphen. What remains are two words from a different Olympic sport. What words are these?

I've cracked this one, and I'll share the solution at the end of this post.

On a personal note: Yours truly is on the verge of becoming Dr. NaturalLanguagePuzzler. Things have been especially busy the last few weeks preparing for my PhD defense, but I plan to post a more detailed breakdown of this puzzle ASAP. I didn't write a complete solver script for this one, but I did use SBERT in masking mode and Word2Vec to generate some candidate words and the solution kind of popped out from there. If I get a chance between frantically editing slides, I'll put together a formal script and walk you through it as usual! :-)

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

shot-putter ---> shot, putter


I know, I know---I too think "shot" is super generic and a bit of a stretch for this puzzle, but this is the best I could come up with and I think it's what Puzzlemaster Will Shortz is asking for here.


Catch you on the next Sunday Puzzle!

--Levi King

Saturday, July 24, 2021

A Flower and a Girl's Name (Solution)

 I'll try to write up my approach soon, but in the meantime:


amaryllis --> Mary, Allis (Alice)

Thursday, July 15, 2021

Country, Company, Competitor (Solution)

Hiya Puzzlers! After a total fail last week, I'm back with a solution for this week's puzzle. That's your spoiler alert---solution is at the end of this post.

I didn't post a preview this week, so I'll do a full breakdown here. Let's see this week's Sunday Puzzle:

This week's challenge comes from listener Peter Collins, of Ann Arbor, Mich. Think of a country. Embedded in consecutive letters is a well-known brand name. The first, second, eighth and ninth letters of the country, in order, spell a former competitor of that brand. Name the country and the brands.

This is quite similar to the puzzle we solved two weeks ago. In that puzzle, there was a Japanese food embedded in the name of a US city, and then the remaining letters could be used to spell a Mexican food. The first part is very similar, but we don't have the unscrambling spelling part this time. So I started my solver script for the current puzzle by recycling the city/foods puzzle solver script.

To solve this puzzle we need:

  • C: a list of countries;
    • This is easy enough to find online, but we've already got this list on hand from previous puzzles; I'm lazily pasting it into my python solver script, i.e., hard coding it;
    • Pro-tip: you'll want to be flexible with what you accept in your list and include variant names; e.g., "Côte d'Ivoire" and "Ivory Coast" and "Republic of Côte d'Ivoire";
    • We'll also want to ASCII-fy this list: e.g., "Côte d'Ivoire" --> "Cote d'Ivoire";
      • I do this in the solver script with slugify, which also lowercases letters;
    • And we'll want to remove any non-letters: "cote d'ivoire" --> "cotedivoire";
    • And we know we need at least 9 letters, so we'll go ahead and filter any shorter strings out of our list;
  • B: a list of brands;
    • I cobbled one together from various lists on the web; I also hard coded directly this into my solver script;
    • We'll want to handle these similarly to the country names: ASCII-fy, remove whitespace and non-letters, and lowercase everything;
From here, there's not a lot of processing to do. Basically, we check each country in C to see if any brand in B appears as a substring, and when we find a match, we get the first, second, eighth and ninth letters of the country, concatenate them in order to get the competitor (all as specified above in the puzzle), and then check to see if the competitor string appears in the list of brands. It's like this:

  • for country in C:
    • for brand in B:
      • if brand in country:
        • competitor = country[0]+country[1]+country[7]+country[8]
          • if competitor in B:
            • print("Solution: "country+" & "+brand+" & "+competitor)

And that's how I solved it! See my script and if you want to see more. I'm posting the solution below.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Saudi Arabia, Audi, Saab

Saturday, July 10, 2021

Plants and Spoonerisms (Solution)

 TBD...

US City, Japanese Food (Solution)

Welcome back. It's time for a solution to the most recent Sunday Puzzle from NPR:

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.

I don't have much to add to the approach I discussed in my preview post, so I'll just link you back to that post, and to my solver script, annotated with comments and posted to the GitHub repo for this blog.

Oh yeah, I have the solution, too, if you just want to see that. Spoiler alert! Scroll down for my solution.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Solution:

Sacramento, ramen, tacos


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

Saturday, June 26, 2021

Car Makes and Girl Names (Solution)

Welcome back, Puzzlers. I'm back to share my solution to the latest Sunday Puzzle from NPR. Scroll to the bottom to see it. Here's the puzzle again:

This week's challenge comes from listener Iva Allen in Canada. Name a make of car. Write it in all capital letters. Rotate one of the letters 90 degrees and another letter 180 degrees to make a woman's name. What is it?

In the preview post, I shared this breakdown:


    What do we need in order to solve this?

    • C: A list of car "makes"; let's assume this means "brands" or "manufacturers";
    • G: A list of girl names;
    • R90: A dictionary mapping of capital letters that can be rotated 90 degrees to form a new letter;
      • {'C': 'U', ...}
    • R180: A dictionary mapping of capital letters that can be rotated 180 degrees to form a new letter;
      • {'M': 'W', ...}
    Now, we iterate through each car maker. Then we'll need to iterate through the letters and determine which ones are in R90 and R180---we make a list of all indices in the string where the letter at that index can be rotated 90 degrees, and another list of indices for 180 degrees. Then we use something like "itertools.product()" to generate all pairs of one 90-degree position and one 180-degree position (where the two positions are not the same---we want to rotate two different letters (indices) in the string). Then we take this "agenda" of pair rotations and apply the rotation mappings to the original string, so we have all possible strings generated from the car maker string. For example:

    ACURA --> ['VUURA', 'AUARA', 'VCCRA']

    Then, we simply iterate through each of these variants and compare it against G, the list of girls' names and print out the car maker and the girl name when find a match.


      And that's how I solved it! If you'd like to see my approach in detail, I've shared my solver script here, and you'll also need my list of car makes and my list of girls' names.

      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .
      .

      MAZDA --> WANDA

      Did you get this solution too?

      See you next week!
      --Levi King

        Monday, June 21, 2021

        Car Makes and Girl Names (Preview)

        Welcome back, Puzzlers. Let's take a crack at the latest Sunday Puzzle from NPR:

        This week's challenge comes from listener Iva Allen in Canada. Name a make of car. Write it in all capital letters. Rotate one of the letters 90 degrees and another letter 180 degrees to make a woman's name. What is it?

        What do we need in order to solve this?

        • C: A list of car "makes"; let's assume this means "brands" or "manufacturers";
        • G: A list of girl names;
        • R90: A dictionary mapping of capital letters that can be rotated 90 degrees to form a new letter;
          • {'C': 'U', ...}
        • R180: A dictionary mapping of capital letters that can be rotated 180 degrees to form a new letter;
          • {'M': 'W', ...}
        Now, we iterate through each car maker. Then we'll need to iterate through the letters and determine which ones are in R90 and R180---we make a list of all indices in the string where the letter at that index can be rotated 90 degrees, and another list of indices for 180 degrees. Then we use something like "itertools.product()" to generate all pairs of one 90-degree position and one 180-degree position (where the two positions are not the same---we want to rotate two different letters (indices) in the string). Then we take this "agenda" of pair rotations and apply the rotation mappings to the original string, so we have all possible strings generated from the car maker string. For example:

        ACURA --> ['VUURA', 'AUARA', 'VCCRA']

        Then, we simply iterate through each of these variants and compare it against G, the list of girls' names and print out the car maker and the girl name when find a match.

        Sounds simple enough, right? I'll be back after the Thursday NPR submission deadline to share my solution. Good luck!

        Thursday, June 17, 2021

        Famous Woman from American History, Famous Athlete (Solution)

        Welcome back, Puzzlers. Spoiler warning: The puzzle solution is posted at the end of this page.

        Ready to solve the latest Sunday Puzzle from NPR?

        This week's challenge comes from listener Sandy Weisz, of Chicago. Name a famous woman in American history with a three-part name. Change one letter in her first name to a double letter. The resulting first and second parts of her name form the first and last names of a famous athlete. And the last part of the woman's name is a major rival of that athlete. Who are these people?

        If you're still working this puzzle, you may want to check my preview post where I discussed the puzzle in more depth.

        We determined that we need these things:

        • W: a list of women from American history; each must have a name that can be represented in three parts;
          • I came up with a pretty short list, so I just included it directly in my solver script;
        • A: a list of famous athletes;
        • fx_double_letter: a function to iterate through the letters in each first name and double OR replace AND double, returning a list of the resulting "names";
        So from there, it's pretty straightforward. We iterate through each woman in W, apply fx_double_letter, check each resulting first and second name against list A; when we find a match, we also need to check the third name for a match in list A. Because I'm only using one list of athletes, I'll need to confirm the "rival" part of the puzzle to be true.

        And that's how I solved it. If you want to try my solver script, you can download it from the companion GitHub repo for this blog, as always.

        As I discussed in the preview, the wording of this puzzle was a little bit tricky.
        The double letter is a different letter; you have to replace the letter and then double it.

        Here's my solution, below:
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        .
        Lady Bird Johnson --> Larry Bird, (Earvin 'Magic') Johnson

        Did you get the same solution?

        See you next week!
        --Levi King

        Monday, June 14, 2021

        Famous Woman from American History, Famous Athlete (Preview)

        Welcome back, Puzzlers. Let's continue our winning streak with the latest Sunday Puzzle from NPR:

        This week's challenge comes from listener Sandy Weisz, of Chicago. Name a famous woman in American history with a three-part name. Change one letter in her first name to a double letter. The resulting first and second parts of her name form the first and last names of a famous athlete. And the last part of the woman's name is a major rival of that athlete. Who are these people?

        I'll preface this by saying that I've already solved it just by doing a little brainstorming, but I'm going to apply my usual systematic approach and try to get the solution that way, too. It's good practice. I'm not going to spoil it here, so you can try to brainstorm for it or implement your own approach.

        Okay, let's break this down. There's some real cagey language in this puzzle. Why does it refer to a "three-part name"? Is that different from "three names"? Is it not just a first, middle and last name? Is there some kind of hyphenation or honorific or nickname involved? We don't really know what that means, so we'll have to be flexible in what possibilities we allow for.

        "Change one letter in her first name to a double letter." I guess we have to assume "first name" here means "first of three parts of her name." The change part of this isn't quite clear, either. Do we just double an existing letter, e.g., Ana --> Anna and Lily --> Lilly? It's worth noting that after glancing through a list of girl's names, there aren't a lot of first names amenable to this transformation. The other way to interpret this clue is that the letter is replaced with a different doubled letter, e.g., Ava --> Anna or Jody --> Jonny. Again, since we don't know, I think it's best if we allow for either interpretation.

        "The resulting first and second parts of her name form the first and last names of a famous athlete." Again, we'll assume this is the first and second parts of the three part name. Is this a man or woman? We don't know.

        "And the last part of the woman's name is a major rival of that athlete." This is the least concerning part--the last name remains a last name.

        What do we need here?

        • W: a list of women from American history; each must have a name that can be represented in three parts;
        • A: a list of famous athletes;
        • fx_double_letter: a function to iterate through the letters in each first name and double OR replace AND double, returning a list of the resulting "names";
        So from there, it's pretty straightforward. We iterate through each woman in W, apply fx_double_letter, check each resulting first and second name against list A; when we find a match, we also need to check the third name for a match in list A. Because I'm only using one list of athletes, I'll need to confirm the "rival" part of the puzzle to be true.

        That's my plan. I'll be back later this week with my solution. Good luck!

        Friday, June 11, 2021

        Country, Capital, Best Picture (Solution)

        Welcome back! I'm happy to report that I "definitely, definitely" solved the latest Sunday Puzzle from NPR. Here's the puzzle, and you can scroll to the bottom of this post for the solution:


        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.

        In the preview, I mentioned that we would need:
        You'll need to the files linked above in order to run my solver script, or you may want to use them in your own script. My solver script is available here on the companion GitHub repository for this blog.
        As discussed in this week's preview post, my approach works like this:

        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)

        Solution:
        Bahrain, Manama --> Rain Man

        See you for the next puzzle!

        --Levi King

        Monday, June 07, 2021

        Country, Capital, Best Picture (Preview)

        Hello Puzzlers. Let's take a crack at the latest Sunday Puzzle from NPR:

        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

        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...