Beat the Puzzle Master Home
Beat the Puzzle Master!
A web site dedicated to solving the NPR Sunday Puzzle

Puzzle August 31, 2008

Podcast of the original challenge

Thinking Phoneticall-EE

Didn't get enough anagrams Sunday? Try these
Challenge: Each word has 2 syllables. The first vowel sound in the first word is a long "E." Change this to a short "E," and phonetically you'll get a new word that answers the second clue. For example: if the clue is "slang term for an eye, and partner for salt," the answer would be: "peeper and pepper."

Clue:
Word 1:
Word 2:

 

From Ken Marx, of Mount Vernon, NY:

Think of a 9-letter word with no repeated letters. The letters in the odd positions (the 1st, 3rd, 5th, 7th and 9th positions) are vowels. All five vowels, A, E, I, O and U, appear once each in some order. What word is this?

How to Solve the Puzzle With Code

This puzzle is quite easy if you have a good word list. Basically, it's a matter of knowing your string functions.

To solve it, you must loop through your list of words and apply three tests to each:
  1. Word length must be nine
  2. The letters at the odd positions must be vowels
  3. There can't be any repeated letters. Note that this simplifies the requirement above, since if there are no repeated letters, then we also know that each of the 5 vowels are used.

Vowels at the Odd Postions

Vowels

Since checking the word length is trivial, we'll jump ahead and work on having vowels in the right places. To do so, we need a loop that steps through the odd numbers, and we need to retrieve letters from the odd position dictated by our loop.

In C# and other languages based on C syntax, such as Perl or Java, it is easy to construct a loop that whips through the odd numbers, like so:

   for (int i = 0; i < 9; i+=2)
This loop starts at 0 and adds two every time.

To fetch the letter at an odd position, we use the substring function, like this:

   string letter = aLine.Substring(i, 1);

Now all we have to do is ensure the letter in question is a vowel and break out of our loop if not. The complete code follows:

    bool hasAll = true;
    //look at letters in the odd positions; if any aren't a vowel, bail
    for (int i = 0; i < 9; i+=2) {
        string letter = aLine.Substring(i, 1);
        if (letter != "a" && letter != "e" && letter
             != "i" && letter != "o" && letter != "u") {
            hasAll = false;
            break;
        }
    }

Determining Whether There are Repeated Letters

There are several ways to determine whether any repeated letters occur, but an easy method is to sort the letters in the word and then loop through, looking at adjoining letters. Sorting places duplicate letters next to each other, so if any two adjoining letters match, we know there are some repeated letters

       //In order to sort, convert to an array:
        char[] allLetters = aLine.ToCharArray();
        Array.Sort(allLetters);
        char c = allLetters[0];
        bool noRepeats = true;
        for (int i = 1; i < 9; i++) {
            if (allLetters[i] == c) {
                noRepeats = false;
                break;
            }
            c = allLetters[i];
        }
At the end of the loop, our bool 'noRepeats' will reflect whether any letter is repeated.

For more detail, download the C# Solution

Solve the Problem in Code!

By clicking the button, you will run a small javascript program in your browser to solve the problem. It needs to fetch the list from the server, and then it should solve the problem in a few seconds. If you're curious, inspect the page source code! (Search for "function famousAmericansFetched".)






Reader Comments

Be the first to comment!

Add a Comment Show comment controls
Comment Details
Your Comment:

Name:
Password:
Your Name*:
Password*:
Confirm*:
Email*: (will not be published!)
  Your Gravatar image
Website?
About Me: