Tuesday, October 2, 2018

Playing NPR's Sunday Puzzle: My First Successful Submission Thanks to LiveCode

I'm a big fan of National Public Radio (NPR) here in the United States. Every Sunday morning on Weekend Edition there is a segment called the Sunday Puzzle hosted by Will Shortz, the puzzle master. Will is a very famous puzzle guru (and ping pong player) who is probably best known for editing the New York Times crossword puzzle.

I'm usually in the kitchen cooking or doing the dishes when the Sunday Puzzle segment airs. Each week it features a "lucky listener" who Will challenges to solve some puzzles on air. Will then challenges all listeners with a weekly puzzle to be solved by Thursday. Will then randomly chooses one of the winning entries to join him on air the next Sunday. I'm really terrible at solving these puzzles. But, I just submitted my first correct answer to a recent puzzle. I solved it largely due to LiveCode.

Here's the puzzle, quoted from the show's transcript:

It comes from listener Jim Levering (ph) of San Antonio, Texas. Think of an affliction in five letters. Shift each letter three spaces later in the alphabet. For example, A would become D. B would become E, et cetera. And the result will be a prominent name in the Bible. Who is it? So again, an affliction in five letters. Shift each letter three spaces later in the alphabet. And the result will be a prominent name in the Bible. Who is it?

This seemed straightforward to me and I quickly determined it was easier to start with names from the Bible and work backwards. What constituted an affliction seemed too vague to me. The few names I thought of did not pan out. Interestingly, the first name I thought of was Judas. (You would think the first name I thought of was Jesus, given my Catholic school upbringing. But, I personally think Judas is one of the most interesting characters in the Bible.)

Following Will's directions above, here is what you get when you transpose Judas:

Judas > graxp

This is certainly not an affliction I'm aware of. After trying a few more names, I gave up and went on to other things. But, for some reason, this puzzle stuck with me over the next few days. Then, as I was falling asleep Wednesday night, it occurred to me that I could easily write a program in LiveCode to transpose every name in the Bible if I could find a web site listing all of the names. The next morning, I quickly found all the Bible names on the Internet (I forgot to write down the link) and wrote the following program in LiveCode.

Here's a screen shot of the app:

The names of the three fields, from left to right, are "alphabet," "names," and "afflictions."

Interestingly, I found one web site with male names and another with the female names. The female names listed the information in this format:

Abigail – mother of Amasa, Sister of David. I Chronicles 2:15-17[1]
Abigail – wife of the wicked Nabal, who became a wife of David after Nabal's death. I Samuel 25[2]
Abihail #1 – mother of Zuriel. (Zuriel was the chief of the house of Merari). Numbers 3:35[3]
Abihail #2 – wife of Abishur and mother of Ahban and Molid. I Chronicles[4]
Abishag – concubine of aged King David. I Kings[5]

But, this posed no problem as I knew I could easily extract just the first word in the line.  And, you might notice that some of the names in the screen shot have a comma in them. I needed to look for that and strip it out if found.

Here is the complete script in the button "Search:"

1:  on mouseup  
2:    put empty into field "total tries"  
3:    put the number of lines in field "names" into L  
4:    put the number of lines in field "alphabet"into A  
5:    put empty into field "affliction"  
6:    repeat with i = 1 to L // Check each word  
7:     put empty into varAffliction  
8:     put line i of field "names" into varLine  
9:     put the first word of varLine into varName  
10:     if the last character of varName is comma then delete the last character of varName  
11:     if the length of varName <> 5 then next repeat  
12:     repeat with j = 1 to 5 //check each letter of word  
13:       put char j of varName into varLetter  
14:       repeat with k = 1 to A // check the alphabet  
15:        if varLetter <> line k of field "alphabet" then next repeat // find the matching letter  
16:        put line k-3 of field "alphabet" into varNewLetter  
17:        if k = 1 then put line 24 of field "alphabet" into varNewLetter  
18:        if k = 2 then put line 25 of field "alphabet" into varNewLetter  
19:        if k = 3 then put line 26 of field "alphabet" into varNewLetter  
20:        put varNewLetter after varAffliction  
21:       end repeat // end check the alphabet  
22:     end repeat // end check each letter of word  
23:     put varName&comma&varAffliction&return after field "affliction"  
24:    end repeat // End check each word  
25:    put the number of lines in field "affliction" into field "total tries"  
26:  end mouseup  

Here are just a few choice explanations of key lines in the script:

There are three repeat loops:

  • Lines 6 to 24 repeat everything for each name found in field "names." 
  • Lines 12 to 22 work on each letter in the name, so this always repeats 5 times.
  • Lines 14-21 do the three letter transposing. 

Here is an explanation of other key lines:

  • Line 9 puts the first word of the line into varName.
  • Line 10 looks to see if there is a comma as the last character. If there is, it deletes it. 
  • Line 11 checks to see if the length of the name is five characters. If it is not, the rest of the code is aborted and the next name in the list is chosen.
  • Line 16 is the transposing engine - once the matching letter is found in field "alphabet," it finds the letter that is three spots ahead of it.
  • Lines 17-19 are hacks. I got lazy - I hadn't had my first cup of coffee yet - and just manually figured out which letter went with a, b, and c.
  • Line 20 builds the newly transposed word.
  • Line 23 puts the Bible name and the transposed word, with a comma in-between, in a new line in the field "affliction."
After clicking the button "Search," it takes LiveCode a few seconds to process the 1964 lines in field "names." Again, I didn't know exactly what affliction I might find, but I figured I could scan the list easily to find one (or more). Here's a screen shot showing the correct answer:

I missed it the first time I scanned the list of 409 matches. But, I found it on the second pass:

Herod > ebola

I was one of 1100 people who submitted the correct answer. Thankfully, I was not chosen as the "lucky listener" to appear on next Sunday's show.


  1. Thanks for posting your submission it will helpful to upcoming people
    Best Play and Pre School for kids in Hyderabad,India. To give your kid a best environment and learning it is the right way to join in play and pre school were kids can build there physically, emotionally and mentally skills developed. We provide programs to kids like Play Group, Nursery, Sanjary Junior, Sanjary Senior and Teacher training Program.
    ­play school in hyderabad

    1. Machine Learning Projects for Final Year machine learning projects for final year

      Deep Learning Projects assist final year students with improving your applied Deep Learning skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include Deep Learning projects for final year into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Deep Learning Projects for Final Year even arrange a more significant compensation.

      Python Training in Chennai Python Training in Chennai Angular Training Project Centers in Chennai

  2. Thanks for posting information
    "Sanjary Academy provides excellent training for Piping design course. Best Piping Design Training Institute in Hyderabad,
    Telangana. We have offer professional Engineering Course like Piping Design Course,QA / QC Course,document Controller
    course,pressure Vessel Design Course, Welding Inspector Course, Quality Management Course, #Safety officer course."
    Piping Design Course
    Piping Design Course in India­
    Piping Design Course in Hyderabad
    QA / QC Course
    QA / QC Course in india
    QA / QC Course in Hyderabad
    Document Controller course
    Pressure Vessel Design Course
    Welding Inspector Course
    Quality Management Course
    Quality Management Course in india
    Safety officer course

  3. Nice Information
    We are the best piping design course in Hyderabad, India. Sanjary academy Offers Piping Design Course and Best Piping Design Training Institute in Hyderabad. Piping Design Institute in India Piping Design Engineering.
    Piping Design Course
    Piping Design Course in india
    Piping Design Course in hyderabad