There is a "Sunday Puzzler" feature of Weekend Edition on NPR Radio on Sundays. The host is Will Shortz, crossword editor of the New York Times. Occasionally, he provides a puzzle that can be solved by exploiting MAGIC string operators and the spell check dictionary, or this week, using the Zip code dictionary and a specially rigged MPI.
The listener challenge from December 8th; deadline for submission Thursday, December 12th at 3pm ET.
"Next week's challenge from listener Pete Collins of Ann Arbor, Michigan: Name a U.S. city in nine letters. Shift the third letter six places later in the alphabet. Then shift the last letter seven places later in the alphabet. The result will be a family name featured in the title of a famous work of fiction. What is the city, and what is the family name?"
We have, in effect, a dictionary of US cities in the MIS.ZIP dictionary and we can check the MRI name index for a last name match to find family names that might solve the puzzle. We will need to cheat a bit on the last count.
First we write an MRI.PAT report using the "actual.name.index" as follows:
We set up the report so that we do an LI selection against a list of last names:
Next, we write a start macro that loops through all the zip codes in MIS.ZIP, picking out all the cities that are nine characters long, and then changing the 3rd and the 9th character as specified and trying to match that new string to any last names in the MPI.
If we get a match, we will build a structure like this:
CITY^/LAST[NEWSTRING] where NEWSTRING has a 3rd and 9th character changed per the puzzle rules.
Hint: I started the report at a hospital in Oregon that appeared to have a complete Zip code dictionary, but found it lacking and had to move the report to a Michigan hospital to solve the puzzle.
The first part of the macro creates a list of nine character cities in a temporary array:
Remember that MAGIC numbers characters in a string starting from zero, so when we need to change the 3rd and 9th characters, we get the characters like this:
CITY#2 = third character
CITY#8 = ninth character
Before we change the string, we change it to all upper case like this:
The ~ is the translate operator and the $L.TO.U is a system string for MAGIC hospitals that will allow the translate to change a to A, b to B, and so on.
In C/S you would use the @Trl2u function like this:
We are supposed to move six down the alphabet for the third character (A becomes G, for example) and seven down the alphabet for the ninth character.
If we take the E(ncode) value of the third character and add six and then take the D(ecode) of that number, we will move six "down" the alphabet. To avoid going past "Z" we check to make sure we are under 91 in the ASCII table.
We make a new string "NEWCITY" by using the $ and % operators to take everything to the left of the 2nd position $2, concatenating the new third character, then concatenating everything to the right of the 2nd position.
We do the same thing with the 9th character, but adding seven rather than six. Because this is the last character, we can just do NEWCITY$8_CHAR^NEWCITY to make the final change.
The final step is to use the new string in the actual name index as the "last.name.indexed" subscript and use the @First() operation to see if there are any patients with that last name in the MPI. You could also use @Next if you did it like this:
@First loops from nil and does not assign back to the subscript
Looking at the object code for @First vs @Next will illustrate:
If we run this report in just the right hospital (with a certain city in the Zip code dictionary) and just the right set of folks in the MPI, we can solve the puzzle:
You have until Thursday 3pm ET to submit an entry.
I actually gave up on the cities in the Oregon hospital’s zip code dictionary after reviewing all the changed nine character strings manually and finding no likely solutions. Next, I got a list of US cities from some internet crossword puzzle dictionary and ran the string transformation against that list and saw that I’d need to find a customer in Michigan and also register some of just the right brothers in their test MPI to get my puzzle report to work.