Solving NPR's Sunday Morning Puzzles with Perl

Lately I've become a fan of the puzzle segment on the Weekend Edition Sunday program on National Public Radio.

Many of the week-long puzzles are amenable to computer solution. Is this cheating? I don't think so. I doubt very many people could solve them without a computer. Since they typically get 300-600 entries each week, I suspect that I'm not the only one using the aid of a machine.

The Perl programming language is especially well suited to solving these puzzles, so I've taken them as an opportunity to practice my skills in that language. (I've been programming in C for over 20 years, and Perl is the first language since C that I've actually found worth learning.)

So here are the puzzles and my Perl scripts to solve them. They're not polished, but then they don't need to be. They generally require you to look at the output and pick the correct answer by eye. But since they've done most of the work, the rest is usually pretty easy.

Most of these scripts need word lists. The stock /usr/dict/english file distributed with Debian Linux is sufficient for some puzzles, but not for all. So I found this much bigger collection: This is a zip archive containing separate files for each length. Note that each entry is capitalized and ends with a cr/lf sequence, so in Perl under UNIX you have to smash case and strip the terminating cr.

Nov 8 1998 puzzle

This is from listener David Laibman of Brooklyn: name a common six-letter word in which every possible combination of four and five consecutive letters is also a word. For example, if you drop the first letter, you're left with a five-letter word; if you drop the last letter, you're left with a five-letter word; if you drop the first two letters, the last two letters, or the first and last letters, you're left with a four-letter word. Every one of these words is very common, and here's a hint: the six-letter word is NOT a plural or a past-tense verb. What word is it?

My answer: scowls

My Perl script

Nov 1 1998 puzzle

Take the word "DEAD-HEADED", it's a hyphenated word. It containes one "H," two "A's," three "E's" and four "D's." In the world of word play this is called a pyramid word because it has the increasing letter frequencies one, two, three and four. Can you think of another 10-letter pyramid word that is a kind of shirt. One letter in it appears once, one twice, one three times and one four times. Hint: the letter that appears just once is a 'V.'

My answer: sleeveless

My Perl script

Oct 25 1998 puzzle

This challenge comes from listener Mark Wilson of Arlington, Massachusetts: Think of an 8-letter word with four vowels in a row, in which, if you remove the four vowels in a row, you're left with the last name of a well-known film actress. Here's a hint: the 8-letter word is a kind of shirt. When you remove the four vowels, reading from left-to-right you're left with the name of the actress. Who is she?

My answer: Hawaiian -> Hawn (as in Goldie Hawn, also Laura Hawn)

My Perl script

Oct 18 1998 puzzle

Write down the word ACCOST. Drop the first two letters, add AR at the end, and you get COSTAR. Now drop the first two letters of COSTAR, add CH at the end, and you get STARCH. Drop the first two letters of STARCH, add ER at the end, and you get ARCHER. Finally, drop the first two letters of ARCHER, add UB at the end, and you get CHERUB. The result is a chain of five common overlapping six-letter words: ACCOST to COSTAR to STARCH to ARCHER to CHERUB. Here's the challenge: starting with the letters CU, can you make a similar chain of five common overlapping six-letter words? What is this chain?

My answer: cubist bistro strode rodent dental

My Perl script

Sept 20 1998 puzzle

This challenge was submitted by listener David Saslav: it's called "NAUGHTY AND NICE". A "nice" letter is defined as any letter in the word NICE, that is, N, I, C, or E. A "naughty" letter is defined as any letter that's not in NICE. "Nice" letters score one point each, "naughty" letters score minus one. Here's the question: what familiar uncapitalized English word has the highest "nice" score? For example, the word FINE has three "nice" letters, I, N, and E, and one "naughty" letter, F. Three minus one is two, so FINE has a score of two. Similarly, NICOTINE has a score of four (six "nice" letters minus two "naughty" letters). Our best score is somewhat higher than that.

My answer: inconvenience

with a score of 9. But because my program only stored a word if it had a better "nice" score than the one previously found, it didn't find "inconveniencing", which also has a score of 9.

My Perl script